Class: EasyTable::Components::Column

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/easy_table/components/column.rb

Instance Method Summary collapse

Methods included from Base

#translate

Constructor Details

#initialize(node, title, label, opts, template, block) ⇒ Column

Returns a new instance of Column.



8
9
10
11
12
13
14
15
16
17
# File 'lib/easy_table/components/column.rb', line 8

def initialize(node, title, label, opts, template, block)
  @node, @title, @label, @template, @block, @opts = node, title, label, template, block, opts
  header_opts = @opts.select { |k, _v| k =~ /^header_.*/ }
  header_opts.each { |k, _v| @opts.delete(k) }
  @header_opts = header_opts.inject({}) do |h, e|
    k, v = *e
    h[k[7..-1]] = v
    h
  end
end

Instance Method Details

#headObject



19
20
21
# File 'lib/easy_table/components/column.rb', line 19

def head
  concat (:th, label, @header_opts)
end

#td(record) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/easy_table/components/column.rb', line 23

def td(record)
  if @block.present?
    html = capture { @block.call(record, self) }
  else
    html = record.send(@title).to_s
  end
  concat((:td, html, html_opts(record)))
end