Module: Rapport::Report
- Defined in:
- lib/rapport/report.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#current_model ⇒ Object
Returns the value of attribute current_model.
-
#options ⇒ Object
Returns the value of attribute options.
-
#section_data ⇒ Object
Returns the value of attribute section_data.
Class Method Summary collapse
Instance Method Summary collapse
- #column_headers ⇒ Object
- #column_symbols ⇒ Object
- #columns ⇒ Object
- #each_row ⇒ Object
- #formatted_cell_value(key, model, row_type) ⇒ Object
- #generate ⇒ Object
- #raw_cell_value(key, model, row_type) ⇒ Object
- #report_generator ⇒ Object
- #row_data ⇒ Object
- #table_name ⇒ Object
- #to_model_class ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#current_model ⇒ Object
Returns the value of attribute current_model.
41 42 43 |
# File 'lib/rapport/report.rb', line 41 def current_model @current_model end |
#options ⇒ Object
Returns the value of attribute options.
41 42 43 |
# File 'lib/rapport/report.rb', line 41 def @options end |
#section_data ⇒ Object
Returns the value of attribute section_data.
41 42 43 |
# File 'lib/rapport/report.rb', line 41 def section_data @section_data end |
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rapport/report.rb', line 4 def self.included(base) base.extend(ClassMethods) base.instance_variable_set(:@columns, []) base.instance_variable_set(:@cell_calculators, {}) def base.inherited(subclass) super(subclass) subclass.instance_variable_set(:@columns, base.instance_variable_get(:@columns).dup ) subclass.instance_variable_set(:@cell_calculators, base.instance_variable_get(:@cell_calculators).dup ) end end |
Instance Method Details
#column_headers ⇒ Object
74 75 76 |
# File 'lib/rapport/report.rb', line 74 def column_headers @_column_headers ||= columns.map{|c| c[0]} end |
#column_symbols ⇒ Object
78 79 80 |
# File 'lib/rapport/report.rb', line 78 def column_symbols @_column_symbols ||= columns.map{|c| c[1]} end |
#columns ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rapport/report.rb', line 66 def columns if @_columns.nil? @_columns = [] self.class.send(:instance_variable_get, :@columns).each {|col| @_columns << col.dup } end @_columns end |
#each_row ⇒ Object
59 60 61 62 63 64 |
# File 'lib/rapport/report.rb', line 59 def each_row each_model do |model, row_type| self.current_model = model # For error reporting yield formatted_row(model, row_type || Rapport.format_underscore(model.class.to_s)) end end |
#formatted_cell_value(key, model, row_type) ⇒ Object
94 95 96 97 |
# File 'lib/rapport/report.rb', line 94 def formatted_cell_value(key, model, row_type) row_data[key] = raw_value = raw_cell_value(key, model, row_type) report_generator.format(cell_format_for(key), raw_value) end |
#generate ⇒ Object
51 52 53 |
# File 'lib/rapport/report.rb', line 51 def generate report_generator.generate end |
#raw_cell_value(key, model, row_type) ⇒ Object
90 91 92 |
# File 'lib/rapport/report.rb', line 90 def raw_cell_value(key, model, row_type) self.row_data[key] = cell_calculator_for(key,row_type).call(model) end |
#report_generator ⇒ Object
47 48 49 |
# File 'lib/rapport/report.rb', line 47 def report_generator @_report_generator ||= ReportGenerator.from(self) end |
#row_data ⇒ Object
43 44 45 |
# File 'lib/rapport/report.rb', line 43 def row_data self.class.row_data end |
#table_name ⇒ Object
86 87 88 |
# File 'lib/rapport/report.rb', line 86 def table_name @table_name ||= [:report_table_name] || "reports_#{Rapport.format_underscore(self.class).sub(/_?report_?/,'')}" end |
#to_model_class ⇒ Object
82 83 84 |
# File 'lib/rapport/report.rb', line 82 def to_model_class @_to_model_class ||= Struct.new("#{self.class}Model", *column_symbols) end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/rapport/report.rb', line 99 def to_s [self.class, [:format]].compact.map{|p| p.to_s }.join(' ') end |