Class: Datagrid::Columns::Column
- Inherits:
-
Object
- Object
- Datagrid::Columns::Column
- Defined in:
- lib/datagrid/columns/column.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #desc_order ⇒ Object
- #format ⇒ Object
- #header ⇒ Object
-
#initialize(grid, name, options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #label ⇒ Object
- #order ⇒ Object
- #value(object) ⇒ Object
- #value_for(object) ⇒ Object
Constructor Details
#initialize(grid, name, options = {}, &block) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 11 |
# File 'lib/datagrid/columns/column.rb', line 6 def initialize(grid, name, = {}, &block) self.grid = grid self.name = name self. = self.block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'lib/datagrid/columns/column.rb', line 4 def block @block end |
#grid ⇒ Object
Returns the value of attribute grid.
4 5 6 |
# File 'lib/datagrid/columns/column.rb', line 4 def grid @grid end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/datagrid/columns/column.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/datagrid/columns/column.rb', line 4 def @options end |
Instance Method Details
#desc_order ⇒ Object
46 47 48 |
# File 'lib/datagrid/columns/column.rb', line 46 def desc_order self.[:desc_order] || (order ? order.to_s + " DESC" : nil) end |
#format ⇒ Object
25 26 27 |
# File 'lib/datagrid/columns/column.rb', line 25 def format self.[:format] end |
#header ⇒ Object
33 34 35 36 |
# File 'lib/datagrid/columns/column.rb', line 33 def header self.[:header] || I18n.translate(self.name, :scope => "reports.#{self.grid}.columns", :default => self.name.to_s.humanize ) end |
#label ⇒ Object
29 30 31 |
# File 'lib/datagrid/columns/column.rb', line 29 def label self.[:label] end |
#order ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/datagrid/columns/column.rb', line 38 def order if .has_key?(:order) self.[:order] else grid.scope.column_names.include?(name.to_s) ? [grid.scope.table_name, name].join(".") : nil end end |
#value(object) ⇒ Object
13 14 15 |
# File 'lib/datagrid/columns/column.rb', line 13 def value(object) value_for(object) end |
#value_for(object) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/datagrid/columns/column.rb', line 17 def value_for(object) if self.block.arity == 1 self.block.call(object) else object.instance_eval(&self.block) end end |