Class: Xporter::Column
- Inherits:
-
Object
- Object
- Xporter::Column
- Defined in:
- lib/xporter/column.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #data(model) ⇒ Object
-
#initialize(attribute_name, title = nil, &block) ⇒ Column
constructor
A new instance of Column.
- #title_from(resource_class) ⇒ Object
Constructor Details
#initialize(attribute_name, title = nil, &block) ⇒ Column
Returns a new instance of Column.
5 6 7 8 9 |
# File 'lib/xporter/column.rb', line 5 def initialize(attribute_name, title = nil, &block) @attribute_name = attribute_name @title = title @block = block || ->(model){ model.public_send(attribute_name) } end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
3 4 5 |
# File 'lib/xporter/column.rb', line 3 def attribute_name @attribute_name end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/xporter/column.rb', line 3 def block @block end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/xporter/column.rb', line 3 def title @title end |
Instance Method Details
#data(model) ⇒ Object
11 12 13 |
# File 'lib/xporter/column.rb', line 11 def data(model) block.call(model) end |
#title_from(resource_class) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/xporter/column.rb', line 15 def title_from(resource_class) return title if title.present? return attribute_name.to_s.titleize unless resource_class.respond_to?(:human_attribute_name) resource_class.human_attribute_name(attribute_name) end |