Class: Tabl::Column

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

Defined Under Namespace

Classes: Formats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args = {}) {|_self| ... } ⇒ Column

Returns a new instance of Column.

Yields:

  • (_self)

Yield Parameters:

  • _self (Tabl::Column)

    the object that the method was called on



7
8
9
10
11
12
13
# File 'lib/tabl/column.rb', line 7

def initialize(name, args = {})
  @name = name
  @label = args[:label] || @name.to_s.titleize
  @value = args[:value] || lambda { |record| record.send(@name) }
  @formats = Formats.new
  yield self if block_given?
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



4
5
6
# File 'lib/tabl/column.rb', line 4

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tabl/column.rb', line 3

def name
  @name
end

#value(record) ⇒ Object



15
16
17
# File 'lib/tabl/column.rb', line 15

def value(record)
  @value.call(record)
end

Instance Method Details

#format(name = nil) ⇒ Object



19
20
21
# File 'lib/tabl/column.rb', line 19

def format(name = nil)
  @formats
end