Class: MagicReport::Report::Csv
- Inherits:
-
Object
- Object
- MagicReport::Report::Csv
- Defined in:
- lib/magic_report/report/csv.rb
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
- #add_headings(report) ⇒ Object
- #add_row(row) ⇒ Object
- #generate ⇒ Object
-
#initialize(report) ⇒ Csv
constructor
A new instance of Csv.
- #io ⇒ Object
-
#unlink ⇒ Object
Don’t forget to unlink in production code.
Constructor Details
#initialize(report) ⇒ Csv
Returns a new instance of Csv.
10 11 12 13 |
# File 'lib/magic_report/report/csv.rb', line 10 def initialize(report) @file = Tempfile.new @csv = ::CSV.new(@file, write_headers: true) end |
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
8 9 10 |
# File 'lib/magic_report/report/csv.rb', line 8 def csv @csv end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/magic_report/report/csv.rb', line 8 def file @file end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
8 9 10 |
# File 'lib/magic_report/report/csv.rb', line 8 def report @report end |
Instance Method Details
#add_headings(report) ⇒ Object
23 24 25 |
# File 'lib/magic_report/report/csv.rb', line 23 def add_headings(report) csv << report.headings end |
#add_row(row) ⇒ Object
27 28 29 |
# File 'lib/magic_report/report/csv.rb', line 27 def add_row(row) csv << row.to_a end |
#generate ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/magic_report/report/csv.rb', line 15 def generate write_headers report.rows.each do |row| csv << row.to_a end end |
#io ⇒ Object
37 38 39 40 41 |
# File 'lib/magic_report/report/csv.rb', line 37 def io io = csv.to_io io.rewind io end |
#unlink ⇒ Object
Don’t forget to unlink in production code
32 33 34 35 |
# File 'lib/magic_report/report/csv.rb', line 32 def unlink file.close file.unlink end |