Class: LpCSVExportable::CSVColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/lp_csv_exportable/csv_column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ CSVColumn

Returns a new instance of CSVColumn.



5
6
7
8
9
10
11
12
# File 'lib/lp_csv_exportable/csv_column.rb', line 5

def initialize(args = {})
  @header = args[:header]
  @model_method = args[:model_method]
  @model_methods = args[:model_methods]
  @type = args.fetch(:type, :string)
  @default_value = args.fetch(:default_value, '')
  after_init(args)
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



3
4
5
# File 'lib/lp_csv_exportable/csv_column.rb', line 3

def default_value
  @default_value
end

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/lp_csv_exportable/csv_column.rb', line 3

def header
  @header
end

#model_methodObject (readonly)

Returns the value of attribute model_method.



3
4
5
# File 'lib/lp_csv_exportable/csv_column.rb', line 3

def model_method
  @model_method
end

#model_methodsObject (readonly)

Returns the value of attribute model_methods.



3
4
5
# File 'lib/lp_csv_exportable/csv_column.rb', line 3

def model_methods
  @model_methods
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/lp_csv_exportable/csv_column.rb', line 3

def type
  @type
end

Instance Method Details

#format(result) ⇒ Object



14
15
16
17
18
# File 'lib/lp_csv_exportable/csv_column.rb', line 14

def format(result)
  return formatted_result(result) if respond_to?(type)
  return default_value if use_default?(result)
  result
end