Class: Csvbuilder::Model::Header

Inherits:
Object
  • Object
show all
Includes:
ColumnShared
Defined in:
lib/csvbuilder/core/internal/model/header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ColumnShared

#options

Constructor Details

#initialize(column_name, row_model_class, context) ⇒ Header

Returns a new instance of Header.



12
13
14
15
16
# File 'lib/csvbuilder/core/internal/model/header.rb', line 12

def initialize(column_name, row_model_class, context)
  @column_name     = column_name
  @row_model_class = row_model_class
  @context         = OpenStruct.new(context)
end

Instance Attribute Details

#column_nameObject (readonly)

Returns the value of attribute column_name.



10
11
12
# File 'lib/csvbuilder/core/internal/model/header.rb', line 10

def column_name
  @column_name
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/csvbuilder/core/internal/model/header.rb', line 10

def context
  @context
end

#row_model_classObject (readonly)

Returns the value of attribute row_model_class.



10
11
12
# File 'lib/csvbuilder/core/internal/model/header.rb', line 10

def row_model_class
  @row_model_class
end

Instance Method Details

#formatted_header(header_name) ⇒ Object



29
30
31
# File 'lib/csvbuilder/core/internal/model/header.rb', line 29

def formatted_header(header_name)
  row_model_class.format_header(header_name, context)
end

#valueObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/csvbuilder/core/internal/model/header.rb', line 18

def value
  case options[:header]
  when Proc
    return options[:header].call(column_name, context)
  when String
    return options[:header]
  end

  formatted_header(column_name.to_s.humanize)
end