Class: DeclarativeGrid::Model::Column
- Inherits:
-
Object
- Object
- DeclarativeGrid::Model::Column
- Defined in:
- lib/declarative_grid/model/column.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Attributes.
-
#name ⇒ Object
Attributes.
-
#options ⇒ Object
Attributes.
Instance Method Summary collapse
-
#header ⇒ Object
Return the header.
-
#initialize(name, options = {}, &block) ⇒ Column
constructor
Constructor.
-
#value_for(record) ⇒ Object
Return the corresponding value of the given record.
Constructor Details
#initialize(name, options = {}, &block) ⇒ Column
Constructor
9 10 11 12 |
# File 'lib/declarative_grid/model/column.rb', line 9 def initialize(name, = {}, &block) self.name, self. = name, self.block = block || lambda {|record| record.send self.name } end |
Instance Attribute Details
#block ⇒ Object
Attributes
6 7 8 |
# File 'lib/declarative_grid/model/column.rb', line 6 def block @block end |
#name ⇒ Object
Attributes
6 7 8 |
# File 'lib/declarative_grid/model/column.rb', line 6 def name @name end |
#options ⇒ Object
Attributes
6 7 8 |
# File 'lib/declarative_grid/model/column.rb', line 6 def @options end |
Instance Method Details
#header ⇒ Object
Return the header
15 16 17 18 19 20 21 22 23 |
# File 'lib/declarative_grid/model/column.rb', line 15 def header header = self.[:header] case header when String, Symbol, Numeric then header when Proc then header.call() when nil then self.name.to_s.humanize else raise DefinitionError, "#{header} is not valid" end end |
#value_for(record) ⇒ Object
Return the corresponding value of the given record
26 27 28 29 30 31 32 |
# File 'lib/declarative_grid/model/column.rb', line 26 def value_for(record) block = self.block case block.arity when 1 then block.call record else raise DefinitionError, "self.#{block} is not valid" end end |