Class: ActiveAdmin::Xls::Builder::Column

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

Overview

Xls column information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block = nil) ⇒ Column

Returns a new instance of Column.

Parameters:

  • name (String, Symbol)

    Name of the column. If the name of the column is an existing attribute of the resource class, the value can be retreived automatically if no block is specified

  • block (Proc) (defaults to: nil)

    A procedure to generate data for the column instead of retreiving the value from the resource directly



281
282
283
284
# File 'lib/active_admin/xls/builder.rb', line 281

def initialize(name, block = nil)
  @name = name
  @data = block || @name
end

Instance Attribute Details

#dataString, ... (readonly)

Returns The column name used to look up the value, or a block used to generate the value to display.

Returns:

  • (String, Symbol, Proc)

    The column name used to look up the value, or a block used to generate the value to display.



291
292
293
# File 'lib/active_admin/xls/builder.rb', line 291

def data
  @data
end

#nameString, Symbol (readonly)

Returns Column name.

Returns:

  • (String, Symbol)

    Column name



287
288
289
# File 'lib/active_admin/xls/builder.rb', line 287

def name
  @name
end

Instance Method Details

#localized_name(i18n_scope = nil) ⇒ Object

Returns a localized version of the column name if a scope is given. Otherwise, it returns the titleized column name without translation.

Parameters:

  • i18n_scope (String, Symbol, Array<String>, Array<Symbol>) (defaults to: nil)

    Translation scope. If not provided, the column name will be used.

See Also:

  • I18n


300
301
302
303
# File 'lib/active_admin/xls/builder.rb', line 300

def localized_name(i18n_scope = nil)
  return name.to_s.titleize unless i18n_scope
  I18n.t name, scope: i18n_scope
end