Class: PaginatedTable::TableDescription::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/paginated_table/view_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



26
27
28
29
30
# File 'lib/paginated_table/view_helpers.rb', line 26

def initialize(name, options = {}, &block)
  @name = name
  @block = block
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/paginated_table/view_helpers.rb', line 24

def name
  @name
end

Instance Method Details

#html_attributesObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/paginated_table/view_helpers.rb', line 48

def html_attributes
  html_attributes = {}
  if @options[:class]
    html_attributes[:class] = Array(@options[:class]).join(' ')
  end
  if @options[:style]
    html_attributes[:style] = @options[:style]
  end
  html_attributes
end

#render_cell(datum) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/paginated_table/view_helpers.rb', line 36

def render_cell(datum)
  if @block
    @block.call(datum)
  else
    datum.send(@name)
  end
end

#render_headerObject



32
33
34
# File 'lib/paginated_table/view_helpers.rb', line 32

def render_header
  @options.fetch(:title, @name.to_s.titleize)
end

#sortable?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/paginated_table/view_helpers.rb', line 44

def sortable?
  @options.fetch(:sortable, true)
end