Class: ExpressTemplates::Components::TableFor::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/express_templates/components/table_for.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



97
98
99
100
101
# File 'lib/express_templates/components/table_for.rb', line 97

def initialize(name, options = {})
  @name = name
  @options = options
  @formatter = options[:formatter]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



96
97
98
# File 'lib/express_templates/components/table_for.rb', line 96

def name
  @name
end

Instance Method Details

#format(item_name) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/express_templates/components/table_for.rb', line 103

def format(item_name)
  if @formatter.nil?
    "\#\{#{item_name}.#{name}\}"
  elsif @formatter.kind_of?(Proc)
    "\#\{(#{@formatter.source}).call(#{item_name}.#{name})\}"
  end
end

#titleObject



111
112
113
# File 'lib/express_templates/components/table_for.rb', line 111

def title
  @name.to_s.try(:titleize)
end