Class: Tabl::Column
- Inherits:
-
Object
- Object
- Tabl::Column
- Defined in:
- lib/tabl/column.rb
Defined Under Namespace
Classes: FormatDsl
Instance Attribute Summary collapse
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #value(record) ⇒ Object
Instance Method Summary collapse
- #format(key = nil, value = nil, record = nil, context = nil) ⇒ Object
-
#initialize(name, args = {}) {|_self| ... } ⇒ Column
constructor
A new instance of Column.
Constructor Details
#initialize(name, args = {}) {|_self| ... } ⇒ Column
Returns a new instance of Column.
8 9 10 11 12 13 14 15 16 |
# File 'lib/tabl/column.rb', line 8 def initialize(name, args = {}) @name = name @label = args[:label] || @name.to_s.titleize @value = args[:value] || lambda { |record| record.send(@name) } @formats = {} @format_dsl = FormatDsl.new(self) yield self if block_given? end |
Instance Attribute Details
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
6 7 8 |
# File 'lib/tabl/column.rb', line 6 def formats @formats end |
#label ⇒ Object
Returns the value of attribute label.
4 5 6 |
# File 'lib/tabl/column.rb', line 4 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tabl/column.rb', line 3 def name @name end |
#value(record) ⇒ Object
18 19 20 |
# File 'lib/tabl/column.rb', line 18 def value(record) @value.call(record) end |
Instance Method Details
#format(key = nil, value = nil, record = nil, context = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tabl/column.rb', line 22 def format(key = nil, value = nil, record = nil, context = nil) if key.nil? return @format_dsl else format = @formats[key] return format unless value if (context) if (format.arity == 1) context.instance_exec(value, &format) else context.instance_exec(value, record, &format) end else if (format.arity == 1) return format.call(value) else return format.call(value, record) end end end end |