Class: SimpleCsvCreator::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#column_nameObject (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_nameObject



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