class IdentifyDependencies
Attributes
circular_reference_check[RW]
current_sheet[RW]
dependencies[RW]
references[RW]
Public Class Methods
new(references = {}, dependencies = {})
click to toggle source
# File src/simplify/identify_dependencies.rb, line 8 def initialize(references = {}, dependencies = {}) @references = references @dependencies = dependencies dependencies.default_proc = lambda do |hash,key| hash[key] = {} end @current_sheet = [] @circular_reference_check = [] end
Public Instance Methods
add_depedencies_for(sheet,cell = :all)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 18 def add_depedencies_for(sheet,cell = :all) if cell == :all references.each do |ref,ast| next unless ref.first == sheet circular_reference_check.clear recursively_add_dependencies_for(sheet,ref.last) end else circular_reference_check.clear recursively_add_dependencies_for(sheet,cell) end end
cell(reference)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 73 def cell(reference) recursively_add_dependencies_for(current_sheet.last,Reference.for(reference).unfix.to_sym) end
circular_reference?(ref)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 50 def circular_reference?(ref) if circular_reference_check.include?(ref) raise ExcelToCodeException.new("Possible circular reference in #{circular_reference_check} #{ref}") else circular_reference_check.push(ref) end false end
map(ast)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 59 def map(ast) return ast unless ast.is_a?(Array) operator = ast[0] if respond_to?(operator) send(operator,*ast[1..-1]) else ast.each {|a| map(a) } end end
recursively_add_dependencies_for(sheet,cell)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 31 def recursively_add_dependencies_for(sheet,cell) return if circular_reference?([sheet, cell]) unless dependencies[sheet].has_key?(cell) dependencies[sheet][cell] = true ast = references[[sheet,cell]] if ast current_sheet.push(sheet) begin map(ast) rescue ExcelToCodeException puts "[:'#{sheet}', :#{cell}] => #{ast}" raise end current_sheet.pop end end circular_reference_check.pop end
sheet_reference(sheet,reference)
click to toggle source
# File src/simplify/identify_dependencies.rb, line 69 def sheet_reference(sheet,reference) recursively_add_dependencies_for(sheet,Reference.for(reference.last).unfix.to_sym) end