Class: ActiveAdmin::CSVBuilder::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/csv_builder.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ humanize_name: true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resource = nil, options = {}, block = nil) ⇒ Column

Returns a new instance of Column.


100
101
102
103
104
# File 'lib/active_admin/csv_builder.rb', line 100

def initialize(name, resource = nil, options = {}, block = nil)
  @options = options.reverse_merge(DEFAULT_OPTIONS)
  @name = humanize_name(name, resource, @options[:humanize_name])
  @data = block || name.to_sym
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data


96
97
98
# File 'lib/active_admin/csv_builder.rb', line 96

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name


96
97
98
# File 'lib/active_admin/csv_builder.rb', line 96

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


96
97
98
# File 'lib/active_admin/csv_builder.rb', line 96

def options
  @options
end

Instance Method Details

#humanize_name(name, resource, humanize_name_option) ⇒ Object


106
107
108
109
110
111
112
# File 'lib/active_admin/csv_builder.rb', line 106

def humanize_name(name, resource, humanize_name_option)
  if humanize_name_option
    name.is_a?(Symbol) && resource.present? ? resource.human_attribute_name(name) : name.to_s.humanize
  else
    name.to_s
  end
end