Class: QueryReport::ColumnModule::Column
- Inherits:
-
Object
- Object
- QueryReport::ColumnModule::Column
- Includes:
- ActionView::Helpers::SanitizeHelper
- 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
- #align ⇒ Object
- #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
- #rowspan_column_humanized ⇒ Object
- #sort_link_attribute ⇒ Object
- #sortable? ⇒ Boolean
- #total ⇒ Object
- #value(record) ⇒ Object
Constructor Details
#initialize(report, column_name, options = {}, block = nil) ⇒ Column
Returns a new instance of Column.
89 90 91 92 93 |
# File 'lib/query_report/column.rb', line 89 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.
87 88 89 |
# File 'lib/query_report/column.rb', line 87 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
87 88 89 |
# File 'lib/query_report/column.rb', line 87 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
87 88 89 |
# File 'lib/query_report/column.rb', line 87 def @options end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
87 88 89 |
# File 'lib/query_report/column.rb', line 87 def report @report end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
87 88 89 |
# File 'lib/query_report/column.rb', line 87 def type @type end |
Instance Method Details
#align ⇒ Object
136 137 138 |
# File 'lib/query_report/column.rb', line 136 def align @options[:align] || (has_total? ? :right : :left) end |
#has_total? ⇒ Boolean
132 133 134 |
# File 'lib/query_report/column.rb', line 132 def has_total? @options[:show_total] == true end |
#humanize ⇒ Object
124 125 126 |
# File 'lib/query_report/column.rb', line 124 def humanize @humanize ||= [:as] || @report.model_class.human_attribute_name(name) end |
#only_on_web? ⇒ Boolean
95 96 97 |
# File 'lib/query_report/column.rb', line 95 def only_on_web? @options[:only_on_web] == true end |
#rowspan? ⇒ Boolean
107 108 109 |
# File 'lib/query_report/column.rb', line 107 def rowspan? @options[:rowspan] == true || @options[:rowspan].kind_of?(Symbol) end |
#rowspan_column_humanized ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/query_report/column.rb', line 111 def rowspan_column_humanized return @rowspan_column_humanized if @rowspan_column_humanized rowspan_column_name = @options[:rowspan].kind_of?(Symbol) ? @options[:rowspan] : self.name report.columns.each do |column| if column.name == rowspan_column_name @rowspan_column_humanized = column.humanize return @rowspan_column_humanized end end @rowspan_column_humanized = self.humanize end |
#sort_link_attribute ⇒ Object
103 104 105 |
# File 'lib/query_report/column.rb', line 103 def sort_link_attribute @options[:sortable] == true ? name : @options[:sortable] end |
#sortable? ⇒ Boolean
99 100 101 |
# File 'lib/query_report/column.rb', line 99 def sortable? @options[:sortable].present? && @options[:sortable] != false end |
#total ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/query_report/column.rb', line 140 def total @total ||= begin if has_total? report.records_with_rowspan.inject(0) do |sum, r| r = report.content_from_element(r[humanize]) r = (r) if r.kind_of? String sum + r.to_f end else nil end end end |
#value(record) ⇒ Object
128 129 130 |
# File 'lib/query_report/column.rb', line 128 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 |