Class: Extract::Sheet
Class Method Summary collapse
Instance Method Summary collapse
- #[](c) ⇒ Object
- #[]=(c, val) ⇒ Object
- #clear_cache! ⇒ Object
- #deps(c) ⇒ Object
- #each_value_comp ⇒ Object
- #eval(str) ⇒ Object
- #raw_value(c) ⇒ Object
Class Method Details
.inline(str) ⇒ Object
87 88 89 |
# File 'lib/extract/sheet.rb', line 87 def inline(str) InlineDef.new(:raw => str).sheet end |
.load(file, sheet_name = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/extract/sheet.rb', line 64 def load(file,sheet_name=nil) w = Roo::Excelx.new(file) w.default_sheet = sheet_name || w.sheets.first sheet = Extract::Sheet.new ("A".."Z").each do |col| (1..100).each do |row| cell_text = w.cell(row,col) val = if cell_text.present? && w.formula?(row,col) "=" + w.formula(row,col).gsub(" ","") else cell_text end loaded = w.cell(row,col) sheet["#{col}#{row}"] = val if val.present? sheet.loaded_values["#{col}#{row}"] = loaded if loaded.present? end end sheet end |
Instance Method Details
#[](c) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/extract/sheet.rb', line 11 def [](c) res = cells[c] #puts "doing #{c} #{res}" if res.to_s =~ /^=/ self.cache[c] ||= Extract::Parser.new(:str => res, :sheet => self).excel_value else res end end |
#[]=(c, val) ⇒ Object
8 9 10 |
# File 'lib/extract/sheet.rb', line 8 def []=(c,val) self.cells[c] = val end |
#clear_cache! ⇒ Object
24 25 26 |
# File 'lib/extract/sheet.rb', line 24 def clear_cache! self.cache = {} end |
#deps(c) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/extract/sheet.rb', line 32 def deps(c) res = cells[c] res = if res.to_s =~ /^=/ d = Extract::Parser.new(:str => res, :sheet => self).deps d.map do |dep| d2 = deps(dep) if d2.empty? dep else d2 end end.flatten else [] end res.flatten.uniq.map do |c| if c =~ /"/ nil else c.gsub("$","") end end.select { |x| x }.sort.uniq end |
#each_value_comp ⇒ Object
56 57 58 59 60 |
# File 'lib/extract/sheet.rb', line 56 def each_value_comp loaded_values.each do |k,v| yield k,cells[k],self[k],v end end |
#eval(str) ⇒ Object
28 29 30 |
# File 'lib/extract/sheet.rb', line 28 def eval(str) Extract::Parser.new(:str => str, :sheet => self).excel_value end |
#raw_value(c) ⇒ Object
20 21 22 |
# File 'lib/extract/sheet.rb', line 20 def raw_value(c) cells[c] end |