Class: WillFilter::Containers::DoubleRange

Inherits:
FilterContainer show all
Defined in:
lib/will_filter/containers/double_range.rb

Instance Attribute Summary collapse

Attributes inherited from FilterContainer

#condition, #filter, #index, #operator, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FilterContainer

#date, #is_floating_point?, #is_numeric?, #options, #reset_values, #sanitized_value, #serialize_to_params, #time, #value

Constructor Details

#initialize(filter, criteria_key, operator, values) ⇒ DoubleRange

Returns a new instance of DoubleRange.



43
44
45
46
47
48
# File 'lib/will_filter/containers/double_range.rb', line 43

def initialize(filter, criteria_key, operator, values)
  super(filter, criteria_key, operator, values)

  @start_value = values[0]
  @end_value = values[1] if values.size > 1
end

Instance Attribute Details

#end_valueObject

Returns the value of attribute end_value.



37
38
39
# File 'lib/will_filter/containers/double_range.rb', line 37

def end_value
  @end_value
end

#start_valueObject

Returns the value of attribute start_value.



37
38
39
# File 'lib/will_filter/containers/double_range.rb', line 37

def start_value
  @start_value
end

Class Method Details

.operatorsObject



39
40
41
# File 'lib/will_filter/containers/double_range.rb', line 39

def self.operators
  [:is_in_the_range]
end

Instance Method Details

#numeric_end_valueObject



65
66
67
# File 'lib/will_filter/containers/double_range.rb', line 65

def numeric_end_value
  end_value.to_f
end

#numeric_start_valueObject



61
62
63
# File 'lib/will_filter/containers/double_range.rb', line 61

def numeric_start_value
  start_value.to_f
end

#sql_conditionObject



69
70
71
# File 'lib/will_filter/containers/double_range.rb', line 69

def sql_condition
  return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
end

#template_nameObject



57
58
59
# File 'lib/will_filter/containers/double_range.rb', line 57

def template_name
  'numeric_range'
end

#validateObject



50
51
52
53
54
55
# File 'lib/will_filter/containers/double_range.rb', line 50

def validate
  return "Start value must be provided" if start_value.blank?
  return "Start value must be a floating point number" unless is_floating_point?(start_value)
  return "End value must be provided" if end_value.blank?
  return "End value must be a floating point number" unless is_floating_point?(end_value)
end