Class: Resque::Reports::CsvReport
- Inherits:
-
BaseReport
- Object
- BaseReport
- Resque::Reports::CsvReport
- Extended by:
- Forwardable
- Includes:
- Callbacks
- Defined in:
- lib/resque/reports/csv_report.rb
Constant Summary collapse
- DEFAULT_CSV_OPTIONS =
{ col_sep: ';', row_sep: "\r\n" }
Constants inherited from BaseReport
Class Attribute Summary collapse
-
.csv_options ⇒ Object
Returns the value of attribute csv_options.
Instance Method Summary collapse
-
#initialize(*args) ⇒ CsvReport
constructor
A new instance of CsvReport.
-
#write(io) ⇒ Object
You must use ancestor methods to work with data: 1) get_data => returns Enumerable of source objects 2) build_table_header => returns Array of column names 3) build_table_row(object) => returns Array of cell values (same order as header).
- #write_line(csv, row_cells) ⇒ Object
Methods inherited from BaseReport
Methods included from Encodings
Constructor Details
#initialize(*args) ⇒ CsvReport
Returns a new instance of CsvReport.
18 19 20 21 |
# File 'lib/resque/reports/csv_report.rb', line 18 def initialize(*args) = DEFAULT_CSV_OPTIONS.merge() super(*args) end |
Class Attribute Details
.csv_options ⇒ Object
Returns the value of attribute csv_options.
9 10 11 |
# File 'lib/resque/reports/csv_report.rb', line 9 def end |
Instance Method Details
#write(io) ⇒ Object
You must use ancestor methods to work with data:
1) get_data => returns Enumerable of source objects
2) build_table_header => returns Array of column names
3) build_table_row(object) => returns Array of cell values (same order as header)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/resque/reports/csv_report.rb', line 31 def write(io) progress = 0 CSV(io, ) do |csv| data_collection = get_data if data_collection.size > 0 write_line csv, build_table_header data_collection.each do |data_element| begin write_line csv, build_table_row(data_element) rescue handle_error end handle_progress(progress += 1) end handle_progress(progress, true) end end end |
#write_line(csv, row_cells) ⇒ Object
55 56 57 |
# File 'lib/resque/reports/csv_report.rb', line 55 def write_line(csv, row_cells) csv << row_cells end |