Class: RubyFromExcel::ArrayingFormulaCell

Inherits:
FormulaCell show all
Defined in:
lib/cells/array/arraying_formula_cell.rb

Instance Attribute Summary collapse

Attributes inherited from FormulaCell

#ast, #original_formula

Attributes inherited from Cell

#dependencies, #reference, #worksheet, #xml_type, #xml_value

Instance Method Summary collapse

Methods inherited from Cell

#can_be_replaced_with_value?, #initialize, #inspect, #test, #to_s, #to_test, #tolerance_for, #value, #value_for_including

Constructor Details

This class inherits a constructor from RubyFromExcel::Cell

Instance Attribute Details

#array_formula_offsetObject

Returns the value of attribute array_formula_offset.



8
9
10
# File 'lib/cells/array/arraying_formula_cell.rb', line 8

def array_formula_offset
  @array_formula_offset
end

#array_formula_referenceObject

Returns the value of attribute array_formula_reference.



7
8
9
# File 'lib/cells/array/arraying_formula_cell.rb', line 7

def array_formula_reference
  @array_formula_reference
end

#array_rangeObject

Returns the value of attribute array_range.



6
7
8
# File 'lib/cells/array/arraying_formula_cell.rb', line 6

def array_range
  @array_range
end

Instance Method Details

#alter_other_cells_if_requiredObject



15
16
17
18
19
# File 'lib/cells/array/arraying_formula_cell.rb', line 15

def alter_other_cells_if_required
 self.array_formula_offset = [0,0]
 self.array_formula_reference = reference.to_ruby + "_array"
 array_formula_from_this_cell_onto_range
end

#array_formula_from_this_cell_onto_rangeObject



21
22
23
24
25
26
27
# File 'lib/cells/array/arraying_formula_cell.rb', line 21

def array_formula_from_this_cell_onto_range
  each_array_formula do |array_formula_reference,value_cell|
    array_cell = ArrayFormulaCell.from_other_cell(value_cell)
    array_formula_onto_cell array_cell
    worksheet.replace_cell(array_formula_reference,array_cell)
  end
end

#array_formula_onto_cell(cell) ⇒ Object



29
30
31
32
33
34
# File 'lib/cells/array/arraying_formula_cell.rb', line 29

def array_formula_onto_cell(cell)
  cell.array_formula_reference = self.array_formula_reference
  cell.array_formula_offset = offset_from(cell)
  cell.original_formula = self.original_formula
  cell.debug_after_sharing
end

#debugObject



70
71
72
# File 'lib/cells/array/arraying_formula_cell.rb', line 70

def debug
  RubyFromExcel.debug(:cells,"#{worksheet.name}.#{reference} -> array -> #{original_formula.inspect} -> #{ast.inspect} offset #{array_formula_offset.inspect} -> #{xml_value} (#{xml_type}) -> #{value_for_including.inspect}")
end

#each_array_formulaObject



49
50
51
52
53
54
# File 'lib/cells/array/arraying_formula_cell.rb', line 49

def each_array_formula
  array_range.to_reference_enum.each do |array_formula_reference|
    next if array_formula_reference == reference.to_s
    yield array_formula_reference, worksheet.cell(array_formula_reference)
  end
end

#offset_from(cell) ⇒ Object



36
37
38
# File 'lib/cells/array/arraying_formula_cell.rb', line 36

def offset_from(cell)
  cell.reference - self.reference
end

#parse_xml(xml) ⇒ Object



10
11
12
13
# File 'lib/cells/array/arraying_formula_cell.rb', line 10

def parse_xml(xml)
  super
  self.array_range = Area.new(worksheet,*xml.at_css("f")['ref'].split(':'))
end

#ruby_array_valueObject



66
67
68
# File 'lib/cells/array/arraying_formula_cell.rb', line 66

def ruby_array_value
  ast.visit(ArrayFormulaBuilder.new(self))
end

#ruby_valueObject



62
63
64
# File 'lib/cells/array/arraying_formula_cell.rb', line 62

def ruby_value
  "@#{reference.to_ruby} ||= #{array_formula_reference}.array_formula_offset(#{array_formula_offset.join(',')})"
end

#to_ruby(r = RubyScriptWriter.new) ⇒ Object



56
57
58
59
60
# File 'lib/cells/array/arraying_formula_cell.rb', line 56

def to_ruby(r = RubyScriptWriter.new)
  r.put_simple_method array_formula_reference, "@#{array_formula_reference} ||= #{ruby_array_value}"
  r.put_simple_method reference.to_ruby, ruby_value
  r.to_s
end

#work_out_dependenciesObject



40
41
42
43
44
45
46
47
# File 'lib/cells/array/arraying_formula_cell.rb', line 40

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 = dependencies_for_array_formula
  end
end