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



283
284
285
286
# File 'lib/active_admin/xls/builder.rb', line 283

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.



293
294
295
# File 'lib/active_admin/xls/builder.rb', line 293

def data
  @data
end

#nameString, Symbol (readonly)

Returns Column name.

Returns:

  • (String, Symbol)

    Column name



289
290
291
# File 'lib/active_admin/xls/builder.rb', line 289

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


302
303
304
305
# File 'lib/active_admin/xls/builder.rb', line 302

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