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
- #humanize ⇒ Object
-
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
constructor
A new instance of Column.
- #only_on_web? ⇒ Boolean
- #value(record) ⇒ Object
Constructor Details
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
Returns a new instance of Column.
24 25 26 27 28 |
# File 'lib/query_report/column.rb', line 24 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 @data = block || column_name.to_sym end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
22 23 24 |
# File 'lib/query_report/column.rb', line 22 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/query_report/column.rb', line 22 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/query_report/column.rb', line 22 def @options end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
22 23 24 |
# File 'lib/query_report/column.rb', line 22 def report @report end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/query_report/column.rb', line 22 def type @type end |
Instance Method Details
#humanize ⇒ Object
34 35 36 |
# File 'lib/query_report/column.rb', line 34 def humanize @humanize ||= [:as] || @report.model_class.human_attribute_name(name) end |
#only_on_web? ⇒ Boolean
30 31 32 |
# File 'lib/query_report/column.rb', line 30 def only_on_web? @options[:only_on_web] == true end |
#value(record) ⇒ Object
38 39 40 |
# File 'lib/query_report/column.rb', line 38 def value(record) self.data.kind_of?(Symbol) ? record.send(self.name) : self.data.call(record) end |