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.



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

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

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



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

def columns
  @columns
end

#nested_rowsObject (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

#headingsObject



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_aObject



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