class ReplaceTableReferences
Attributes
sheet_name[RW]
Public Class Methods
replace(*args)
click to toggle source
# File src/simplify/replace_table_references.rb, line 65 def self.replace(*args) self.new.replace(*args) end
Public Instance Methods
replace(input,table_data,output)
click to toggle source
# File src/simplify/replace_table_references.rb, line 69 def replace(input,table_data,output) tables = {} table_data.each do |line| table = Table.new(*line.strip.split("\t")) tables[table.name.downcase] = table end rewriter = ReplaceTableReferenceAst.new(tables,sheet_name) input.each_line do |line| # Looks to match shared string lines begin if line =~ /\[(:table_reference|:local_table_reference)/ cols = line.split("\t") ast = cols.pop ref = cols.first rewriter.referring_cell = ref output.puts "#{cols.join("\t")}\t#{rewriter.map(eval(ast)).inspect}" else output.puts line end rescue Exception => e puts "Exception at line #{line}" raise end end end