Class: SimpleCsvCreator::Column
- Inherits:
-
Object
- Object
- SimpleCsvCreator::Column
- Defined in:
- lib/simple_csv_creator/column.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
Instance Method Summary collapse
- #human_name ⇒ Object
-
#initialize(column_name, &block) ⇒ Column
constructor
A new instance of Column.
- #value(resource) ⇒ Object
Constructor Details
#initialize(column_name, &block) ⇒ Column
Returns a new instance of Column.
4 5 6 7 |
# File 'lib/simple_csv_creator/column.rb', line 4 def initialize(column_name, &block) @column_name = column_name @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/simple_csv_creator/column.rb', line 3 def block @block end |
#column_name ⇒ Object (readonly)
Returns the value of attribute column_name.
3 4 5 |
# File 'lib/simple_csv_creator/column.rb', line 3 def column_name @column_name end |
Instance Method Details
#human_name ⇒ Object
9 10 11 |
# File 'lib/simple_csv_creator/column.rb', line 9 def human_name column_name.is_a?(Symbol) ? titleize(column_name.to_s) : column_name end |
#value(resource) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/simple_csv_creator/column.rb', line 13 def value(resource) if block block.call(resource) else resource.public_send(column_name) end end |