Class: Arrolio::Content::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/table.rb

Defined Under Namespace

Classes: Cell, Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header: [], body: [], column_widths: nil, style_id: :table, id: nil) ⇒ Table

Returns a new instance of Table.



8
9
10
11
12
13
14
15
16
# File 'lib/arrolio/content/table.rb', line 8

def initialize(header: [], body: [], column_widths: nil,
               style_id: :table, id: nil)
  @header = header.map { |row| coerce_row(row) }.freeze
  @body = body.map { |row| coerce_row(row) }.freeze
  @column_widths = column_widths&.map(&:to_f)&.freeze
  @style_id = style_id.to_sym
  @id = id
  freeze
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/arrolio/content/table.rb', line 6

def body
  @body
end

#column_widthsObject (readonly)

Returns the value of attribute column_widths.



6
7
8
# File 'lib/arrolio/content/table.rb', line 6

def column_widths
  @column_widths
end

#headerObject (readonly)

Returns the value of attribute header.



6
7
8
# File 'lib/arrolio/content/table.rb', line 6

def header
  @header
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/arrolio/content/table.rb', line 6

def id
  @id
end

#style_idObject (readonly)

Returns the value of attribute style_id.



6
7
8
# File 'lib/arrolio/content/table.rb', line 6

def style_id
  @style_id
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



26
27
28
29
30
31
32
33
# File 'lib/arrolio/content/table.rb', line 26

def ==(other)
  other.is_a?(self.class) &&
    header == other.header &&
    body == other.body &&
    column_widths == other.column_widths &&
    style_id == other.style_id &&
    id == other.id
end

#column_countObject



22
23
24
# File 'lib/arrolio/content/table.rb', line 22

def column_count
  rows.map { |r| r.cells.length }.max || 0
end

#hashObject



37
38
39
# File 'lib/arrolio/content/table.rb', line 37

def hash
  [self.class, header, body, column_widths, style_id, id].hash
end

#rowsObject



18
19
20
# File 'lib/arrolio/content/table.rb', line 18

def rows
  @header + @body
end