Class: Reportinator::Row

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

config, #config, logger, #logger

Methods included from Helpers

#merge_hash, #merge_hash!, #symbolize_attributes

Instance Attribute Details

#columnsObject



5
6
7
# File 'lib/reportinator/report/row.rb', line 5

def columns
  @columns ||= []
end

Class Method Details

.create(input) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/reportinator/report/row.rb', line 9

def self.create(input)
  row = new
  if input.instance_of? Array
    input.each { |value| row.insert value }
  else
    row.insert(input)
  end
  row
end

Instance Method Details

#insert(data, position = :last) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/reportinator/report/row.rb', line 19

def insert(data, position = :last)
  column = create_column(data)
  return columns.prepend(column) if position == :first
  return columns.insert(position, column) if position.is_a? Numeric
  return columns.append(column) if position == :last
  raise "Invalid Position!"
end

#outputObject



32
33
34
# File 'lib/reportinator/report/row.rb', line 32

def output
  columns.map { |c| c.output }
end

#totalObject



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

def total
  numeric_columns = columns.select { |c| c.numeric? }
  numeric_columns.sum { |c| c.output }
end