Permalink
Browse files

Fix the incorrect pruning of arraying formulas

  • Loading branch information...
1 parent 3822fa4 commit 76a4fe3ee61f3f212f8059376eb37229ef746302 @tamc committed Oct 30, 2011
Binary file not shown.
@@ -39,9 +39,10 @@ def offset_from(cell)
def work_out_dependencies
super
+ dependencies_for_array_formula = [reference.to_ruby(true)] + self.dependencies
each_array_formula do |array_formula_reference,array_cell|
next unless array_cell
- array_cell.dependencies = self.dependencies
+ array_cell.dependencies = dependencies_for_array_formula
end
end
View
@@ -23,7 +23,7 @@ def alter_other_cells_if_required
def work_out_dependencies
self.dependencies = []
end
-
+
def to_ruby(r = RubyScriptWriter.new)
r.put_simple_method reference.to_ruby, ruby_value
r.to_s
@@ -48,6 +48,8 @@ def delete_cells_that_we_dont_want_to_keep
sheet.cells.delete_if do |reference,cell|
if cells_to_keep.has_key?(cell.to_s)
false
+ #elsif cell.must_keep?
+ # false
else
RubyFromExcel.debug(:pruning_delete,"#{name}.#{reference}")
true
View
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.add_dependency('rubyscriptwriter','>= 0.0.1')
s.add_dependency('rubypeg','>= 0.0.2')
s.required_ruby_version = "~>1.9.1"
- s.version = '0.0.14'
+ s.version = '0.0.15'
s.author = "Thomas Counsell, Green on Black Ltd"
s.email = "ruby-from-excel@greenonblack.com"
s.homepage = "http://github.com/tamc/rubyfromexcel"
@@ -29,7 +29,7 @@
it "should know its dependencies, and also apply them to the cells that it arrays with" do
array_cell = mock(:array_cell)
- array_cell.should_receive(:dependencies=).with(["sheet1.a3", "sheet1.a4", "sheet1.a5", "sheet1.a6", "sheet1.d2", "sheet1.e2"])
+ array_cell.should_receive(:dependencies=).with((["sheet1.b3", "sheet1.a3", "sheet1.a4", "sheet1.a5", "sheet1.a6", "sheet1.d2", "sheet1.e2"]))
@worksheet.should_receive(:cell).with('c3').and_return(array_cell)
@arraying_cell.work_out_dependencies
@arraying_cell.dependencies.should == ["sheet1.a3", "sheet1.a4", "sheet1.a5", "sheet1.a6", "sheet1.d2", "sheet1.e2"]
@@ -10,19 +10,39 @@
it "should be able prune any cells not required" do
workbook = mock(:workbook)
workbook.should_receive(:work_out_dependencies)
+
sheet1 = mock(:worksheet,:name =>'sheet1')
- workbook.should_receive(:worksheets).at_least(:once).and_return({'sheet1' => sheet1})
- workbook.should_receive(:total_cells).and_return(2)
- cell1 = mock(:cell,:worksheet => sheet1,:reference => 'c1')
- sheet1.should_receive(:cells).at_least(:once).and_return({'a1' => cell1})
- cell1.should_receive(:dependencies).and_return(['sheet1.a2'])
- cell2 = mock(:cell,:worksheet => sheet1,:reference => 'c2')
- workbook.should_receive(:cell).with('sheet1.a2').and_return(cell2)
+ sheet2 = mock(:worksheet,:name =>'sheet2')
+
+ workbook.should_receive(:worksheets).at_least(:once).and_return({'sheet1' => sheet1,'sheet2' => sheet2})
+ workbook.should_receive(:total_cells).and_return(3)
+
+ cell1 = mock(:cell,:worksheet => sheet1,:reference => 'a1')
+ #workbook.should_receive(:cell).with('sheet1.a1').and_return(cell1)
+ cell1.should_receive(:dependencies).and_return(['sheet2.a2'])
+
+ cell2 = mock(:cell,:worksheet => sheet2,:reference => 'a2')
+ workbook.should_receive(:cell).with('sheet2.a2').and_return(cell2)
cell2.should_receive(:dependencies).and_return([])
+
+ cell3 = mock(:cell,:worksheet => sheet2,:reference => 'a3')
+ #workbook.should_receive(:cell).with('sheet2.a3').and_return(cell3)
+ #cell3.should_receive(:dependencies).and_return(['sheet1.a1'])
+
+ sheet1_cells = {'a1' => cell1}
+ sheet2_cells = {'a2' => cell2,'a3' => cell3}
+ sheet1.should_receive(:cells).at_least(:once).and_return(sheet1_cells)
+ sheet2.should_receive(:cells).at_least(:once).and_return(sheet2_cells)
+
SheetNames.instance.clear
SheetNames.instance['Output Sheet'] = 'sheet1'
- workbook.work_out_dependencies
+
wb = WorkbookPruner.new(workbook)
+ workbook.work_out_dependencies
wb.prune_cells_not_needed_for_output_sheets('Output Sheet')
+
+ sheet1_cells.should have_key('a1')
+ sheet2_cells.should have_key('a2')
+ sheet2_cells.should_not have_key('a3')
end
end

0 comments on commit 76a4fe3

Please sign in to comment.