Class: Workbook::Table

Inherits:
Array
  • Object
show all
Includes:
Modules::TableDiffSort, Writers::CsvTableWriter
Defined in:
lib/workbook/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Writers::CsvTableWriter

#to_csv

Methods included from Modules::TableDiffSort

#align, #align_row, #diff, #diff_template, #insert_placeholder?, #placeholder_row

Constructor Details

#initialize(row_cel_values = [], sheet = nil, options = {}) ⇒ 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, options={}
  #@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, options)
    end
  end
  self.sheet = sheet
  # Column data is considered as a 'row' with 'cells' that contain 'formatting'

end

Instance Attribute Details

#headerObject

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

#sheetObject

Returns the value of attribute sheet



9
10
11
# File 'lib/workbook/table.rb', line 9

def sheet
  @sheet
end

Instance Method Details

#contains_row?(row) ⇒ Boolean

Raises:

  • (ArgumentError)


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

#create_or_open_row_at(index) ⇒ Object



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

#has_contents?Boolean



57
58
59
# File 'lib/workbook/table.rb', line 57

def has_contents?
  self.clone.remove_empty_lines!.count != 0
end

#new_row(cel_values = []) ⇒ Object

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

#remove_empty_lines!Object



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