Class: Workbook::Table
- Inherits:
-
Array
- Object
- Array
- Workbook::Table
- Includes:
- Modules::TableDiffSort, Writers::CsvTableWriter
- Defined in:
- lib/workbook/table.rb
Instance Attribute Summary (collapse)
-
- (Object) header
Returns the value of attribute header.
-
- (Object) sheet
Returns the value of attribute sheet.
Instance Method Summary (collapse)
- - (Boolean) contains_row?(row)
- - (Object) create_or_open_row_at(index)
- - (Boolean) has_contents?
-
- (Table) initialize(row_cel_values = [], sheet = nil, options = {})
constructor
A new instance of Table.
-
- (Object) new_row(cel_values = [])
factory pattern...?.
- - (Object) remove_empty_lines!
Methods included from Writers::CsvTableWriter
Methods included from Modules::TableDiffSort
#align, #align_row, #diff, #diff_template, #insert_placeholder?, #placeholder_row
Constructor Details
- (Table) initialize(row_cel_values = [], sheet = nil, options = {})
A new instance of Table
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/workbook/table.rb', line 12 def initialize row_cel_values=[], sheet=nil, ={} #@rows = [] row_cel_values = [] if row_cel_values == nil row_cel_values.each do |r| if r.is_a? Workbook::Row r.table = self else r = Workbook::Row.new(r,self, ) end end self.sheet = sheet # Column data is considered as a 'row' with 'cells' that contain 'formatting' end |
Instance Attribute Details
- (Object) header
Returns the value of attribute header
10 11 12 13 14 15 16 17 18 |
# File 'lib/workbook/table.rb', line 10 def header if @header == false false elsif @header @header else first end end |
- (Object) sheet
Returns the value of attribute sheet
9 10 11 |
# File 'lib/workbook/table.rb', line 9 def sheet @sheet end |
Instance Method Details
- (Boolean) contains_row?(row)
61 62 63 64 |
# File 'lib/workbook/table.rb', line 61 def contains_row? row raise ArgumentError, "table should be a Workbook::Row (you passed a #{t.class})" unless row.is_a?(Workbook::Row) self.collect{|r| r.object_id}.include? row.object_id end |
- (Object) create_or_open_row_at(index)
43 44 45 46 47 48 49 50 |
# File 'lib/workbook/table.rb', line 43 def create_or_open_row_at index r = self[index] if r == nil r = Workbook::Row.new r.table=(self) end r end |
- (Boolean) has_contents?
57 58 59 |
# File 'lib/workbook/table.rb', line 57 def has_contents? self.clone.remove_empty_lines!.count != 0 end |
- (Object) new_row(cel_values = [])
factory pattern...?
38 39 40 41 |
# File 'lib/workbook/table.rb', line 38 def new_row cel_values=[] r = Workbook::Row.new(cel_values,self) return r end |
- (Object) remove_empty_lines!
52 53 54 55 |
# File 'lib/workbook/table.rb', line 52 def remove_empty_lines! self.delete_if{|r| r.nil? or r.compact.empty?} self end |