Class: DeclarativeGrid::Model::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_grid/model/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Column

Constructor



9
10
11
12
# File 'lib/declarative_grid/model/column.rb', line 9

def initialize(name, options = {}, &block)
  self.name, self.options = name, options
  self.block = block || lambda {|record| record.send self.name }
end

Instance Attribute Details

#blockObject

Attributes



6
7
8
# File 'lib/declarative_grid/model/column.rb', line 6

def block
  @block
end

#nameObject

Attributes



6
7
8
# File 'lib/declarative_grid/model/column.rb', line 6

def name
  @name
end

#optionsObject

Attributes



6
7
8
# File 'lib/declarative_grid/model/column.rb', line 6

def options
  @options
end

Instance Method Details

#headerObject

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.options[: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