Class: Warped::Table::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/warped/table/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter_name, display_name = nil, method: nil, **options) ⇒ Column

Returns a new instance of Column.

Parameters:

  • parameter_name (String)

    The parameter name to be used by the column

  • display_name (String) (defaults to: nil)

    The display name of the column

  • method (String, Symbol, Proc) (defaults to: nil)

    The method to be called on the record to get the content of the column



14
15
16
17
18
19
# File 'lib/warped/table/column.rb', line 14

def initialize(parameter_name, display_name = nil, method: nil, **options)
  @parameter_name = parameter_name
  @display_name = display_name
  @options = options
  @method = method.presence || parameter_name
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/warped/table/column.rb', line 9

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/warped/table/column.rb', line 9

def options
  @options
end

#parameter_nameObject (readonly)

Returns the value of attribute parameter_name.



9
10
11
# File 'lib/warped/table/column.rb', line 9

def parameter_name
  @parameter_name
end

Instance Method Details

#content_for(record) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/warped/table/column.rb', line 25

def content_for(record)
  if method.is_a?(Proc)
    method.call(record)
  else
    record.public_send(method)
  end
end

#display_nameObject



21
22
23
# File 'lib/warped/table/column.rb', line 21

def display_name
  @display_name.presence || parameter_name.to_s.humanize
end