Class: Tableficate::Filter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tableficate/filters/base.rb

Direct Known Subclasses

CollectionBase, Input, InputRange, SelectRange

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, name, options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tableficate/filters/base.rb', line 6

def initialize(table, name, options = {})
  @table = table
  @name  = name

  @label         = options.delete(:label) || table.columns.detect{|column| column.name == @name}.try(:header) || name.to_s.titleize
  @label_options = options.delete(:label_options) || {}
  @attrs         = options

  @template   = 'filters/' + self.class.name.demodulize.underscore
  @field_name = "#{table.as}[filter][#{@name}]"
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def attrs
  @attrs
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def field_name
  @field_name
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def label
  @label
end

#label_optionsObject (readonly)

Returns the value of attribute label_options.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def label_options
  @label_options
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def name
  @name
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def table
  @table
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/tableficate/filters/base.rb', line 4

def template
  @template
end

Instance Method Details

#field_value(params) ⇒ Object



18
19
20
# File 'lib/tableficate/filters/base.rb', line 18

def field_value(params)
  params[:filter][@name] rescue ''
end