Class: Trestle::Table::Column

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

Defined Under Namespace

Classes: Renderer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



6
7
8
9
# File 'lib/trestle/table/column.rb', line 6

def initialize(field, options={}, &block)
  @field, @options = field, options
  @block = block if block_given?
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def block
  @block
end

#fieldObject (readonly)

Returns the value of attribute field.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def field
  @field
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def options
  @options
end

Instance Method Details

#renderer(table:, template:) ⇒ Object



11
12
13
# File 'lib/trestle/table/column.rb', line 11

def renderer(table:, template:)
  Renderer.new(self, table: table, template: template)
end

#sort_fieldObject



19
20
21
22
23
24
25
# File 'lib/trestle/table/column.rb', line 19

def sort_field
  if options[:sort].is_a?(Hash)
    options[:sort][:field] || field
  else
    options[:sort] || field
  end
end

#sort_optionsObject



27
28
29
# File 'lib/trestle/table/column.rb', line 27

def sort_options
  options[:sort].is_a?(Hash) ? options[:sort] : {}
end

#sortable?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/trestle/table/column.rb', line 15

def sortable?
  options[:sort] != false && (!@block || options.has_key?(:sort))
end