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
18
19
20
21
# File 'lib/easy_table/components/column.rb', line 8

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

Instance Method Details

#headObject



23
24
25
# File 'lib/easy_table/components/column.rb', line 23

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

#td(record) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/easy_table/components/column.rb', line 27

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