Class: RubyFromExcel::SharedFormulaDependencyBuilder

Inherits:
DependencyBuilder show all
Defined in:
lib/optimiser/shared_formula_dependency_builder.rb

Instance Attribute Summary collapse

Attributes inherited from DependencyBuilder

#dependencies, #formula_cell, #worksheet

Instance Method Summary collapse

Methods inherited from DependencyBuilder

#formula, #local_table_reference, #named_reference, #reference_for_name, #sheet_reference, #table_reference, #using_worksheet, #workbook

Constructor Details

#initialize(formula_cell = nil, shared_formula_offset = nil) ⇒ SharedFormulaDependencyBuilder

Returns a new instance of SharedFormulaDependencyBuilder.


6
7
8
9
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 6

def initialize(formula_cell = nil, shared_formula_offset = nil)
  super formula_cell
  self.shared_formula_offset = shared_formula_offset
end

Instance Attribute Details

#shared_formula_offsetObject

Returns the value of attribute shared_formula_offset


4
5
6
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 4

def shared_formula_offset
  @shared_formula_offset
end

Instance Method Details

#area(start_area, end_area) ⇒ Object


27
28
29
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 27

def area(start_area,end_area)
  self.dependencies.concat Area.new(worksheet,Reference.new(start_area).shift!(shared_formula_offset).to_ruby,Reference.new(end_area).shift!(shared_formula_offset).to_ruby).dependencies
end

#area_without_offsetObject


25
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 25

alias area_without_offset area

#cell(reference) ⇒ Object


11
12
13
14
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 11

def cell(reference)
  self.dependencies << Reference.new(reference,worksheet).shift!(shared_formula_offset).to_ruby(true)
  Reference.new(reference).to_ruby
end

#dependencies_for(full_reference) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 31

def dependencies_for(full_reference)
  return [] unless full_reference  =~ /(sheet\d+)\.(.*)/
  sheet_name, reference = $1, $2
  using_worksheet(sheet_name) do
    case reference
    when /a\('(.*?)','(.*?)'\)/; area_without_offset($1,$2)
    else; self.dependencies << full_reference
    end
  end    
end

#function(name, *args) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/optimiser/shared_formula_dependency_builder.rb', line 16

def function(name,*args)
  if name == "INDIRECT"
    args.first.visit(self)
    dependencies_for SharedFormulaBuilder.new(formula_cell,shared_formula_offset).indirect_function(args.first)
  else
    args.each { |a| a.visit(self) }
  end
end