Class: TableSortable::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/table_sortable/column.rb,
lib/table_sortable/column/filter.rb,
lib/table_sortable/column/sorter.rb

Defined Under Namespace

Classes: Filter, Sorter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(col_name, *options) ⇒ Column

Returns a new instance of Column.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/table_sortable/column.rb', line 6

def initialize(col_name, *options)

  options = options.extract_options!
  value = options[:value] || col_name
  label = options[:label] || (options[:label] == false ? '' : col_name.to_s.titleize)
  placeholder = options[:placeholder] || (options[:placeholder] == false ? false : label)
  template = options[:template] || col_name

  @name = col_name
  @value = value.is_a?(Proc) ? value : -> (record) { record.send(value) }
  @label = label
  @placeholder = placeholder
  @template = template
  @filter = TableSortable::Column::Filter.new(options.merge(:column_name => @name) )
  @sorter = TableSortable::Column::Sorter.new(options.merge(:column_name => @name) )

end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



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

def filter
  @filter
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



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

def placeholder
  @placeholder
end

#sorterObject (readonly)

Returns the value of attribute sorter.



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

def sorter
  @sorter
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#value(record) ⇒ Object



24
25
26
# File 'lib/table_sortable/column.rb', line 24

def value(record)
  record.instance_eval(&@value) unless @value.nil?
end