Class: SimpleTable::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, name, options = {}) ⇒ Column

Returns a new instance of Column.



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

def initialize(table, name, options = {})
  @table = table
  @name = name
  @value = options.delete(:value)
  @options = options.dup || {}
  @options[:class] ||= name
  @options[:id] ||= "#{name.to_s.downcase}_header" if name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/simple_table/column.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/simple_table/column.rb', line 3

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/simple_table/column.rb', line 3

def table
  @table
end

Instance Method Details

#attribute_nameObject



22
23
24
# File 'lib/simple_table/column.rb', line 22

def attribute_name
  name.to_s.underscore
end

#contentObject



14
15
16
# File 'lib/simple_table/column.rb', line 14

def content
  name.is_a?(Symbol) ? translate(name) : name
end

#translate(content) ⇒ Object



18
19
20
# File 'lib/simple_table/column.rb', line 18

def translate(content)
  table.view.t(:".columns.#{name}", :default => '')
end