Class: ArFinderForm::Attr::RangeAttrs

Inherits:
Base
  • Object
show all
Defined in:
lib/ar_finder_form/attr/range_attrs.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#array_separator, #column, #name, #nil_available, #options

Instance Method Summary collapse

Methods inherited from Base

#client_class_eval, #column_name, #column_type_cast, #form_value, #form_value_array, #match?, #nil_available?, #table

Constructor Details

#initialize(column, name, options) ⇒ RangeAttrs

Returns a new instance of RangeAttrs.



7
8
9
10
11
12
13
14
# File 'lib/ar_finder_form/attr/range_attrs.rb', line 7

def initialize(column, name, options)
  super(column, name, options)
  range = options[:range] || {}
  min_def = {:operator => '>='}.update(range[:min] || options[:min] || {})
  max_def = {:operator => '<='}.update(range[:max] || options[:max] || {})
  @min = Simple.new(column, min_def[:attr] || "#{name}_min", min_def)
  @max = Simple.new(column, max_def[:attr] || "#{name}_max", max_def)
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



6
7
8
# File 'lib/ar_finder_form/attr/range_attrs.rb', line 6

def max
  @max
end

#minObject

Returns the value of attribute min.



6
7
8
# File 'lib/ar_finder_form/attr/range_attrs.rb', line 6

def min
  @min
end

Instance Method Details

#build(context) ⇒ Object



21
22
23
24
25
26
# File 'lib/ar_finder_form/attr/range_attrs.rb', line 21

def build(context)
  sub_context = context.new_sub_context(:connector => 'AND')
  @min.build(sub_context)
  @max.build(sub_context)
  context.merge(sub_context)
end

#setupObject



16
17
18
19
# File 'lib/ar_finder_form/attr/range_attrs.rb', line 16

def setup
  @min.setup
  @max.setup
end