class Extract::SheetDefinition

Attributes

sheet[RW]

Public Class Methods

load(file,output,sheet_name=nil) click to toggle source
# File lib/extract/sheet_definition.rb, line 144
def load(file,output,sheet_name=nil)
  res = new
  res.sheet = Sheet.load(file,sheet_name)
  res.output_cells = output
  res
end

Public Instance Methods

[](c) click to toggle source
# File lib/extract/sheet_definition.rb, line 102
def [](c)
  sheet[c]
end
deps(cell,ops={}) click to toggle source
# File lib/extract/sheet_definition.rb, line 53
def deps(cell,ops={})
  raw = sheet.deps(cell)
  if ops[:table]
    res = []
    raw.each do |c|
      t = tables.for_cell(c)
      res << (t || c)
    end
    res.uniq.sort
  else
    raw
  end
end
each_input() { |cell, cell_names,sheet| ... } click to toggle source
# File lib/extract/sheet_definition.rb, line 109
def each_input
  input_cells.each do |cell|
    yield cell, cell_names[cell],sheet[cell]
  end
end
each_other() { |c,cell_names,sheet,cells,d| ... } click to toggle source
# File lib/extract/sheet_definition.rb, line 136
def each_other
  each_other_basic do |c|
    d = sheet.deps(c)
    yield c,cell_names[c],sheet[c],sheet.cells[c],d
  end
end
each_other_basic() { |c| ... } click to toggle source
# File lib/extract/sheet_definition.rb, line 121
def each_other_basic
  res = []
  bad = input_cells + output_cells
  sheet.cells.each do |k,v|
    if !bad.include?(k)
      res << k
    end
  end

  res.each do |c|
    d = sheet.deps(c)
    yield c if sheet.cells[c].present? && d.size > 0
  end
end
each_output() { |cell, cell_names,sheet,dep_map,cells| ... } click to toggle source
# File lib/extract/sheet_definition.rb, line 115
def each_output
  output_cells.sort.each do |cell|
    yield cell, cell_names[cell],sheet[cell],dep_map[cell],sheet.cells[cell]
  end
end
left(c) click to toggle source
# File lib/extract/sheet_definition.rb, line 14
def left(c)
  col = c[0..0]
  row = c[1..-1]
  col = prev_letter(col)
  "#{col}#{row}"
end
output_cells=(arr) click to toggle source
# File lib/extract/sheet_definition.rb, line 35
def output_cells=(arr)
  @output_cells = Extract.expand_cells(arr).uniq
end
prev_letter(letter) click to toggle source
# File lib/extract/sheet_definition.rb, line 8
def prev_letter(letter)
  r = ("A".."Z").to_a
  raise "bad letter #{letter}" unless r.index(letter)
  i = r.index(letter) - 1
  r[i]
end
raw_value(c) click to toggle source
# File lib/extract/sheet_definition.rb, line 105
def raw_value(c)
  sheet.cells[c]
end
save!(res=nil) click to toggle source
# File lib/extract/sheet_definition.rb, line 95
def save!(res=nil)
  res ||= Persist::Sheet.new
  setup_persisted_sheet! res
  res.save!
  res
end
setup_persisted_sheet!(res=nil) click to toggle source
# File lib/extract/sheet_definition.rb, line 75
def setup_persisted_sheet!(res=nil)
  res.cells = {}
  res.input_cells = []
  res.output_cells = []

  sheet.cells.each do |k,v|
    res.cells[k] = v
  end

  input_cells.each do |c|
    res.input_cells << c
  end

  output_cells.each do |c|
    res.output_cells << c
  end

  res
end