Class: Slamdown::Conversion::Tables::Layout
- Inherits:
-
Object
- Object
- Slamdown::Conversion::Tables::Layout
- Defined in:
- lib/slamdown/conversion/tables.rb
Overview
Holds one format-specific grouping of a format-neutral source table after the shared grid algorithm has run.
Instance Attribute Summary collapse
-
#body_groups ⇒ Object
readonly
Returns the value of attribute body_groups.
-
#complexity_reason ⇒ Object
readonly
Returns the value of attribute complexity_reason.
-
#foot_rows ⇒ Object
readonly
Returns the value of attribute foot_rows.
-
#head_rows ⇒ Object
readonly
Returns the value of attribute head_rows.
Instance Method Summary collapse
- #complexity_limited? ⇒ Boolean
- #expanded_row(node) ⇒ Object
-
#initialize(head_rows, body_groups, foot_rows) ⇒ Layout
constructor
A new instance of Layout.
- #ragged_padded? ⇒ Boolean
- #rectangular? ⇒ Boolean
- #rows ⇒ Object
Constructor Details
#initialize(head_rows, body_groups, foot_rows) ⇒ Layout
Returns a new instance of Layout.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/slamdown/conversion/tables.rb', line 62 def initialize(head_rows, body_groups, foot_rows) @ragged_padded = false rows = head_rows + body_groups.flatten + foot_rows if rows.length > MAX_ROWS set_limited(:row_count) return end , @complexity_reason = (rows) if complexity_limited? set_empty_groups freeze return end , @ragged_padded, padding_error = pad_ragged_rows(rows, ) if padding_error set_limited(padding_error) return end @head_rows = map_rows(head_rows, ) @body_groups = body_groups.map { |group| map_rows(group, ) }.freeze @foot_rows = map_rows(foot_rows, ) @expanded_by_node_id = rows.each_with_object({}) { |row, result| result[row.node.object_id] = .fetch(row.object_id) }.freeze freeze end |
Instance Attribute Details
#body_groups ⇒ Object (readonly)
Returns the value of attribute body_groups.
60 61 62 |
# File 'lib/slamdown/conversion/tables.rb', line 60 def body_groups @body_groups end |
#complexity_reason ⇒ Object (readonly)
Returns the value of attribute complexity_reason.
60 61 62 |
# File 'lib/slamdown/conversion/tables.rb', line 60 def complexity_reason @complexity_reason end |
#foot_rows ⇒ Object (readonly)
Returns the value of attribute foot_rows.
60 61 62 |
# File 'lib/slamdown/conversion/tables.rb', line 60 def foot_rows @foot_rows end |
#head_rows ⇒ Object (readonly)
Returns the value of attribute head_rows.
60 61 62 |
# File 'lib/slamdown/conversion/tables.rb', line 60 def head_rows @head_rows end |
Instance Method Details
#complexity_limited? ⇒ Boolean
97 98 99 |
# File 'lib/slamdown/conversion/tables.rb', line 97 def complexity_limited? !complexity_reason.nil? end |
#expanded_row(node) ⇒ Object
105 106 107 |
# File 'lib/slamdown/conversion/tables.rb', line 105 def (node) @expanded_by_node_id[node.object_id] end |
#ragged_padded? ⇒ Boolean
101 102 103 |
# File 'lib/slamdown/conversion/tables.rb', line 101 def ragged_padded? @ragged_padded end |
#rectangular? ⇒ Boolean
92 93 94 95 |
# File 'lib/slamdown/conversion/tables.rb', line 92 def rectangular? widths = rows.map(&:length) !widths.empty? && widths.first > 0 && widths.uniq.length == 1 && rows.none? { |row| row.any?(&:nil?) } end |
#rows ⇒ Object
88 89 90 |
# File 'lib/slamdown/conversion/tables.rb', line 88 def rows head_rows + body_groups.inject([]) { |result, group| result + group } + foot_rows end |