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, caption: nil, footnotes: []) ⇒ Table

Returns a new instance of Table.



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

def initialize(header: [], body: [], column_widths: nil,
               style_id: :table, id: nil, caption: nil, footnotes: [])
  @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
  @caption = caption
  @footnotes = Array(footnotes).freeze
  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

#captionObject (readonly)

Returns the value of attribute caption.



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

def caption
  @caption
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

#footnotesObject (readonly)

Returns the value of attribute footnotes.



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

def footnotes
  @footnotes
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?



32
33
34
35
36
37
38
39
40
# File 'lib/arrolio/content/table.rb', line 32

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 &&
    footnotes == other.footnotes
end

#column_countObject

Colspan-aware column count. Rowspan can still hide columns (a row covered from above has fewer cells); Table::Grid is the authoritative count for layout.



28
29
30
# File 'lib/arrolio/content/table.rb', line 28

def column_count
  rows.map { |r| r.cells.sum(&:colspan) }.max || 0
end

#hashObject



44
45
46
# File 'lib/arrolio/content/table.rb', line 44

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

#rowsObject



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

def rows
  @header + @body
end