Class: WillFilter::Containers::NumericRange
- Inherits:
-
FilterContainer
- Object
- FilterContainer
- WillFilter::Containers::NumericRange
- Defined in:
- lib/will_filter/containers/numeric_range.rb
Instance Attribute Summary collapse
-
#end_value ⇒ Object
Returns the value of attribute end_value.
-
#start_value ⇒ Object
Returns the value of attribute start_value.
Attributes inherited from FilterContainer
#condition, #filter, #index, #operator, #values
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filter, criteria_key, operator, values) ⇒ NumericRange
constructor
A new instance of NumericRange.
- #numeric_end_value ⇒ Object
- #numeric_start_value ⇒ Object
- #sql_condition ⇒ Object
- #validate ⇒ Object
Methods inherited from FilterContainer
#date, #is_floating_point?, #is_numeric?, #options, #reset_values, #sanitized_value, #serialize_to_params, #template_name, #time, #value
Constructor Details
#initialize(filter, criteria_key, operator, values) ⇒ NumericRange
Returns a new instance of NumericRange.
42 43 44 45 46 47 |
# File 'lib/will_filter/containers/numeric_range.rb', line 42 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_value ⇒ Object
Returns the value of attribute end_value.
36 37 38 |
# File 'lib/will_filter/containers/numeric_range.rb', line 36 def end_value @end_value end |
#start_value ⇒ Object
Returns the value of attribute start_value.
36 37 38 |
# File 'lib/will_filter/containers/numeric_range.rb', line 36 def start_value @start_value end |
Class Method Details
.operators ⇒ Object
38 39 40 |
# File 'lib/will_filter/containers/numeric_range.rb', line 38 def self.operators [:is_in_the_range] end |
Instance Method Details
#numeric_end_value ⇒ Object
60 61 62 |
# File 'lib/will_filter/containers/numeric_range.rb', line 60 def numeric_end_value end_value.to_i end |
#numeric_start_value ⇒ Object
56 57 58 |
# File 'lib/will_filter/containers/numeric_range.rb', line 56 def numeric_start_value start_value.to_i end |
#sql_condition ⇒ Object
64 65 66 |
# File 'lib/will_filter/containers/numeric_range.rb', line 64 def sql_condition return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range end |
#validate ⇒ Object
49 50 51 52 53 54 |
# File 'lib/will_filter/containers/numeric_range.rb', line 49 def validate return "Start value must be provided" if start_value.blank? return "Start value must be numeric" unless is_numeric?(start_value) return "End value must be provided" if end_value.blank? return "End value must be numeric" unless is_numeric?(end_value) end |