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
- #rowspan? ⇒ Boolean
- #sortable? ⇒ Boolean
- #total ⇒ Object
- #value(record) ⇒ Object
Constructor Details
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
Returns a new instance of Column.
49 50 51 52 53 |
# File 'lib/query_report/column.rb', line 49 def initialize(report, column_name, ={}, block = nil) @report, @name, @options = report, column_name, @type = @report.model_class.columns_hash[column_name.to_s].try(:type) || [:type] || :string rescue :string @data = block || column_name.to_sym end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
47 48 49 |
# File 'lib/query_report/column.rb', line 47 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
47 48 49 |
# File 'lib/query_report/column.rb', line 47 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
47 48 49 |
# File 'lib/query_report/column.rb', line 47 def @options end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
47 48 49 |
# File 'lib/query_report/column.rb', line 47 def report @report end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
47 48 49 |
# File 'lib/query_report/column.rb', line 47 def type @type end |
Instance Method Details
#has_total? ⇒ Boolean
75 76 77 |
# File 'lib/query_report/column.rb', line 75 def has_total? @options[:show_total] == true end |
#humanize ⇒ Object
67 68 69 |
# File 'lib/query_report/column.rb', line 67 def humanize @humanize ||= [:as] || @report.model_class.human_attribute_name(name) end |
#only_on_web? ⇒ Boolean
55 56 57 |
# File 'lib/query_report/column.rb', line 55 def only_on_web? @options[:only_on_web] == true end |
#rowspan? ⇒ Boolean
63 64 65 |
# File 'lib/query_report/column.rb', line 63 def rowspan? @options[:rowspan] == true end |
#sortable? ⇒ Boolean
59 60 61 |
# File 'lib/query_report/column.rb', line 59 def sortable? @options[:sortable] == true end |
#total ⇒ Object
79 80 81 |
# File 'lib/query_report/column.rb', line 79 def total @total ||= has_total? ? report.records.inject(0) {|sum, r| sum + (r[humanize].nil? ? 0 : r[humanize]) } : nil end |
#value(record) ⇒ Object
71 72 73 |
# File 'lib/query_report/column.rb', line 71 def value(record) self.data.kind_of?(Symbol) ? (record.respond_to?(self.name) ? record.send(self.name) : record[self.name]) : self.data.call(record) end |