class SortIntoCalculationOrder
Attributes
current_sheet[RW]
ordered_references[RW]
references[RW]
Public Instance Methods
add_ordered_references_for(ref)
click to toggle source
# File src/simplify/sort_into_calculation_order.rb, line 30 def add_ordered_references_for(ref) sheet = ref.first cell = ref.last current_sheet.push(sheet) ast = @references[ref] map(ast) current_sheet.pop @ordered_references << ref @counted[ref] = true end
cell(reference)
click to toggle source
# File src/simplify/sort_into_calculation_order.rb, line 59 def cell(reference) ref = [current_sheet.last, reference.to_s.gsub('$','').to_sym] return if @counted.has_key?(ref) add_ordered_references_for(ref) end
map(ast)
click to toggle source
# File src/simplify/sort_into_calculation_order.rb, line 41 def map(ast) return ast unless ast.is_a?(Array) operator = ast[0] if respond_to?(operator) send(operator,*ast[1..-1]) else ast[1..-1].each do |a| map(a) end end end
sheet_reference(sheet,reference)
click to toggle source
# File src/simplify/sort_into_calculation_order.rb, line 53 def sheet_reference(sheet,reference) ref = [sheet, reference.last.to_s.gsub('$','').to_sym] return if @counted.has_key?(ref) add_ordered_references_for(ref) end
sort(references)
click to toggle source
FIXME: Probably not the best algorithm for this
# File src/simplify/sort_into_calculation_order.rb, line 9 def sort(references) @current_sheet = [] @ordered_references = [] @counted = {} @references = references # First we find the references that are at the top of the tree references_with_counts = CountFormulaReferences.new.count(references) tops = [] references_with_counts.each do |reference, count| next unless count == 0 tops << reference end # Then we have to work through those tops # recursively adding the cells that they depend on tops.each do |reference| add_ordered_references_for reference end @ordered_references end