Class: Arrolio::Content::Table
- Inherits:
-
Object
- Object
- Arrolio::Content::Table
- Defined in:
- lib/arrolio/content/table.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#column_widths ⇒ Object
readonly
Returns the value of attribute column_widths.
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#style_id ⇒ Object
readonly
Returns the value of attribute style_id.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#column_count ⇒ Object
Colspan-aware column count.
- #hash ⇒ Object
-
#initialize(header: [], body: [], column_widths: nil, style_id: :table, id: nil, caption: nil, footnotes: []) ⇒ Table
constructor
A new instance of Table.
- #rows ⇒ Object
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/arrolio/content/table.rb', line 6 def body @body end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
6 7 8 |
# File 'lib/arrolio/content/table.rb', line 6 def caption @caption end |
#column_widths ⇒ Object (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 |
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
6 7 8 |
# File 'lib/arrolio/content/table.rb', line 6 def footnotes @footnotes end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/arrolio/content/table.rb', line 6 def header @header end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/arrolio/content/table.rb', line 6 def id @id end |
#style_id ⇒ Object (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_count ⇒ Object
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 |
#hash ⇒ Object
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 |
#rows ⇒ Object
21 22 23 |
# File 'lib/arrolio/content/table.rb', line 21 def rows @header + @body end |