Class: Reportinator::Report
- Inherits:
-
Base
- Object
- Base
- Reportinator::Report
show all
- Defined in:
- lib/reportinator/report/report.rb
Instance Attribute 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
#rows ⇒ Object
5
6
7
|
# File 'lib/reportinator/report/report.rb', line 5
def rows
@rows ||= []
end
|
Instance Method Details
#insert(row, position = :last) ⇒ Object
9
10
11
12
13
|
# File 'lib/reportinator/report/report.rb', line 9
def insert(row, position = :last)
return insert_row(row, position) if row.instance_of? Row
raise "Invalid row data: #{row}" unless row.instance_of? Array
row.each { |r| insert_row(r) }
end
|
#insert_row(row, position = :last) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/reportinator/report/report.rb', line 15
def insert_row(row, position = :last)
raise "Not a row" unless row.instance_of? Row
return rows.append(row) if position == :last
return rows.prepend(row) if position == :first
return rows.insert(position, row) if position.is_a? Numeric
raise "Invalid Position!"
end
|
#output ⇒ Object
23
24
25
|
# File 'lib/reportinator/report/report.rb', line 23
def output
rows.map { |r| r.output }
end
|
#to_csv ⇒ Object
27
28
29
30
31
|
# File 'lib/reportinator/report/report.rb', line 27
def to_csv
CSV.generate do |csv|
output.each { |row| csv << row }
end
end
|