Class: MagicReport::GeneralReport
- Inherits:
-
Object
- Object
- MagicReport::GeneralReport
- Defined in:
- lib/magic_report/general_report.rb
Instance Attribute Summary collapse
-
#csv ⇒ Object
readonly
Returns the value of attribute csv.
-
#fill ⇒ Object
readonly
Returns the value of attribute fill.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
-
#report_klass ⇒ Object
readonly
Returns the value of attribute report_klass.
Instance Method Summary collapse
- #as_attachment ⇒ Object
- #generate ⇒ Object
-
#initialize(input, report_klass, options = {}) ⇒ GeneralReport
constructor
A new instance of GeneralReport.
Constructor Details
#initialize(input, report_klass, options = {}) ⇒ GeneralReport
Returns a new instance of GeneralReport.
7 8 9 10 11 12 |
# File 'lib/magic_report/general_report.rb', line 7 def initialize(input, report_klass, = {}) @models = input.is_a?(Enumerable) ? input : [input] @report_klass = report_klass @csv = ::MagicReport::Report::Csv.new(self) @fill = [:fill] || false end |
Instance Attribute Details
#csv ⇒ Object (readonly)
Returns the value of attribute csv.
5 6 7 |
# File 'lib/magic_report/general_report.rb', line 5 def csv @csv end |
#fill ⇒ Object (readonly)
Returns the value of attribute fill.
5 6 7 |
# File 'lib/magic_report/general_report.rb', line 5 def fill @fill end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
5 6 7 |
# File 'lib/magic_report/general_report.rb', line 5 def models @models end |
#report_klass ⇒ Object (readonly)
Returns the value of attribute report_klass.
5 6 7 |
# File 'lib/magic_report/general_report.rb', line 5 def report_klass @report_klass end |
Instance Method Details
#as_attachment ⇒ Object
23 24 25 26 27 28 |
# File 'lib/magic_report/general_report.rb', line 23 def ||= { mime_type: "text/csv", content: csv.io.read } end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/magic_report/general_report.rb', line 14 def generate models.find_each.with_index do |model, index| report = report_klass.new(model, fill) csv.add_headings(report) if index.zero? report.rows.each { |row| csv.add_row(row) } end end |