Class: MagicReport::Report::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_report/report/row.rb

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRow

Returns a new instance of Row.



28
29
30
31
# File 'lib/magic_report/report/row.rb', line 28

def initialize
  @columns = []
  @nested_rows = {}
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



26
27
28
# File 'lib/magic_report/report/row.rb', line 26

def columns
  @columns
end

#nested_rowsObject (readonly)

Returns the value of attribute nested_rows.



26
27
28
# File 'lib/magic_report/report/row.rb', line 26

def nested_rows
  @nested_rows
end

Instance Method Details

#add_column_value(key:, value:) ⇒ Object



33
34
35
# File 'lib/magic_report/report/row.rb', line 33

def add_column_value(key:, value:)
  @columns.find { |column| column.key == key }.assign_value(value)
end

#add_nested_row(key:, row:) ⇒ Object



37
38
39
# File 'lib/magic_report/report/row.rb', line 37

def add_nested_row(key:, row:)
  nested_rows[key] = row
end

#headingsObject



45
46
47
# File 'lib/magic_report/report/row.rb', line 45

def headings
  (columns.map(&:full_heading) + nested_rows.values.map(&:headings)).flatten
end

#register_column(key, heading, is_primary, prefix = nil) ⇒ Object



41
42
43
# File 'lib/magic_report/report/row.rb', line 41

def register_column(key, heading, is_primary, prefix = nil)
  @columns << Column.new(key, heading, is_primary, prefix)
end

#to_aObject



49
50
51
# File 'lib/magic_report/report/row.rb', line 49

def to_a
  (columns.map(&:value) + nested_rows.values.map(&:to_a)).flatten
end