Class: Extract::SheetDefinition
- Includes:
- FromHash
- Defined in:
- lib/extract/sheet_definition.rb
Instance Attribute Summary collapse
-
#sheet ⇒ Object
Returns the value of attribute sheet.
Class Method Summary collapse
Instance Method Summary collapse
- #[](c) ⇒ Object
- #deps(cell, ops = {}) ⇒ Object
- #each_input ⇒ Object
- #each_other ⇒ Object
- #each_other_basic ⇒ Object
- #each_output ⇒ Object
- #left(c) ⇒ Object
- #output_cells=(arr) ⇒ Object
- #prev_letter(letter) ⇒ Object
- #raw_value(c) ⇒ Object
- #save!(res = nil) ⇒ Object
- #setup_persisted_sheet!(res = nil) ⇒ Object
Instance Attribute Details
#sheet ⇒ Object
Returns the value of attribute sheet.
4 5 6 |
# File 'lib/extract/sheet_definition.rb', line 4 def sheet @sheet end |
Class Method Details
Instance Method Details
#[](c) ⇒ Object
102 103 104 |
# File 'lib/extract/sheet_definition.rb', line 102 def [](c) sheet[c] end |
#deps(cell, ops = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
109 110 111 112 113 |
# 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 ⇒ Object
136 137 138 139 140 141 |
# 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 ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# 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 ⇒ Object
115 116 117 118 119 |
# 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) ⇒ Object
14 15 16 17 18 19 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/extract/sheet_definition.rb', line 35 def output_cells=(arr) @output_cells = Extract.(arr).uniq end |
#prev_letter(letter) ⇒ Object
8 9 10 11 12 13 |
# 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) ⇒ Object
105 106 107 |
# File 'lib/extract/sheet_definition.rb', line 105 def raw_value(c) sheet.cells[c] end |
#save!(res = nil) ⇒ Object
95 96 97 98 99 100 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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 |