Class: QueryReport::ColumnModule::Column
- Inherits:
-
Object
- Object
- QueryReport::ColumnModule::Column
- Defined in:
- lib/query_report/column.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #has_total? ⇒ Boolean
- #humanize ⇒ Object
-
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
constructor
A new instance of Column.
- #only_on_web? ⇒ Boolean
- #sortable? ⇒ Boolean
- #total ⇒ Object
- #value(record) ⇒ Object
Constructor Details
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
Returns a new instance of Column.
48 49 50 51 52 |
# File 'lib/query_report/column.rb', line 48 def initialize(report, column_name, ={}, block = nil) @report, @name, = report, column_name, @type = @report.model_class.columns_hash[column_name.to_s].try(:type) || [:type] || :string @data = block || column_name.to_sym end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
46 47 48 |
# File 'lib/query_report/column.rb', line 46 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/query_report/column.rb', line 46 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
46 47 48 |
# File 'lib/query_report/column.rb', line 46 def end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
46 47 48 |
# File 'lib/query_report/column.rb', line 46 def report @report end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
46 47 48 |
# File 'lib/query_report/column.rb', line 46 def type @type end |
Instance Method Details
#has_total? ⇒ Boolean
70 71 72 |
# File 'lib/query_report/column.rb', line 70 def has_total? [:show_total] == true end |
#humanize ⇒ Object
62 63 64 |
# File 'lib/query_report/column.rb', line 62 def humanize @humanize ||= [:as] || @report.model_class.human_attribute_name(name) end |
#only_on_web? ⇒ Boolean
54 55 56 |
# File 'lib/query_report/column.rb', line 54 def only_on_web? [:only_on_web] == true end |
#sortable? ⇒ Boolean
58 59 60 |
# File 'lib/query_report/column.rb', line 58 def sortable? [:sortable] == true end |
#total ⇒ Object
74 75 76 |
# File 'lib/query_report/column.rb', line 74 def total @total ||= has_total? ? report.records.inject(0) {|sum, r| sum + r[humanize] } : nil end |
#value(record) ⇒ Object
66 67 68 |
# File 'lib/query_report/column.rb', line 66 def value(record) self.data.kind_of?(Symbol) ? record.send(self.name) : self.data.call(record) end |