Class: MagicReport::Report::Row
- Inherits:
-
Object
- Object
- MagicReport::Report::Row
- Defined in:
- lib/magic_report/report/row.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#nested_rows ⇒ Object
readonly
Returns the value of attribute nested_rows.
Instance Method Summary collapse
- #add_column_value(key:, value:) ⇒ Object
- #add_nested_row(key:, row:) ⇒ Object
- #headings ⇒ Object
-
#initialize ⇒ Row
constructor
A new instance of Row.
- #register_column(key, heading, prefix = nil) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Row
Returns a new instance of Row.
27 28 29 30 |
# File 'lib/magic_report/report/row.rb', line 27 def initialize @columns = [] @nested_rows = {} end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
25 26 27 |
# File 'lib/magic_report/report/row.rb', line 25 def columns @columns end |
#nested_rows ⇒ Object (readonly)
Returns the value of attribute nested_rows.
25 26 27 |
# File 'lib/magic_report/report/row.rb', line 25 def nested_rows @nested_rows end |
Instance Method Details
#add_column_value(key:, value:) ⇒ Object
32 33 34 |
# File 'lib/magic_report/report/row.rb', line 32 def add_column_value(key:, value:) @columns.find { |column| column.key == key }.assign_value(value) end |
#add_nested_row(key:, row:) ⇒ Object
36 37 38 |
# File 'lib/magic_report/report/row.rb', line 36 def add_nested_row(key:, row:) nested_rows[key] = row end |
#headings ⇒ Object
44 45 46 |
# File 'lib/magic_report/report/row.rb', line 44 def headings (columns.map(&:full_heading) + nested_rows.values.map(&:headings)).flatten end |
#register_column(key, heading, prefix = nil) ⇒ Object
40 41 42 |
# File 'lib/magic_report/report/row.rb', line 40 def register_column(key, heading, prefix = nil) @columns << Column.new(key, heading, prefix) end |
#to_a ⇒ Object
48 49 50 |
# File 'lib/magic_report/report/row.rb', line 48 def to_a (columns.map(&:value) + nested_rows.values.map(&:to_a)).flatten end |