Class: Refine::Conditions::NumericCondition
- Inherits:
-
Condition
- Object
- Condition
- Refine::Conditions::NumericCondition
show all
- Includes:
- ActiveModel::Validations, HasClauses
- Defined in:
- app/models/refine/conditions/numeric_condition.rb
Constant Summary
collapse
- CLAUSE_EQUALS =
Clauses::EQUALS
- CLAUSE_DOESNT_EQUAL =
Clauses::DOESNT_EQUAL
- CLAUSE_LESS_THAN_OR_EQUAL =
Clauses::LESS_THAN_OR_EQUAL
- CLAUSE_LESS_THAN =
Clauses::LESS_THAN
- CLAUSE_GREATER_THAN =
Clauses::GREATER_THAN
- CLAUSE_GREATER_THAN_OR_EQUAL =
Clauses::GREATER_THAN_OR_EQUAL
- CLAUSE_BETWEEN =
Clauses::BETWEEN
- CLAUSE_NOT_BETWEEN =
Clauses::NOT_BETWEEN
- CLAUSE_SET =
Clauses::SET
- CLAUSE_NOT_SET =
Clauses::NOT_SET
- I18N_PREFIX =
"refine.refine_blueprints.numeric_condition."
SupportsFlatQueries::LEFT_JOIN_CLAUSES
Instance Attribute Summary collapse
Attributes inherited from Condition
#attribute, #before_validations, #clause, #display, #ensurances, #filter, #id, #is_flat_query, #is_refinement
Instance Method Summary
collapse
-
#allow_floats ⇒ Object
-
#apply_clause_between(table, value1, value2) ⇒ Object
-
#apply_clause_doesnt_equal(table, value) ⇒ Object
-
#apply_clause_equals(table, value) ⇒ Object
-
#apply_clause_greater_than(table, value) ⇒ Object
-
#apply_clause_greater_than_or_equal(table, value) ⇒ Object
-
#apply_clause_less_than(table, value) ⇒ Object
-
#apply_clause_less_than_or_equal(table, value) ⇒ Object
-
#apply_clause_not_between(table, value1, value2) ⇒ Object
-
#apply_clause_not_set(table) ⇒ Object
-
#apply_clause_set(table) ⇒ Object
-
#apply_condition(input, table, _inverse_clause) ⇒ Object
TODO Refactor to remove input here.
-
#boot ⇒ Object
-
#clauses ⇒ Object
-
#component ⇒ Object
-
#floats_not_allowed? ⇒ Boolean
-
#human_readable(input) ⇒ Object
-
#human_readable_value(input) ⇒ Object
-
#input_could_include_zero?(input) ⇒ Boolean
-
#set_input_parameters(input) ⇒ Object
Methods included from HasClauses
#before_clause_validation, #boot_has_clauses, #clause_display_map, #custom_clauses, #ensure_clause, #ensure_clauses, #get_clause_by_id, #get_clauses, included, #only_clauses, #remap_clause_displays, #update_show_clauses, #with_clauses, #without_clauses
Methods inherited from Condition
#add_ensurance, #add_messages, #add_rules, #apply, #approved_clauses, #before_validate, #boot_traits, #call_proc_if_callable, #clause_display, #clause_exists?, #clause_in_approved_list?, #ensure_attribute_configured, #ensure_id, #evaluated_meta, #initialize, #messages, #recursively_evaluate_lazy_enumerable, #run_before_validate_validations, #run_ensurance_validations, #set_filter, #to_array, #update_value, #validate_user_input, #with_display
#add_pending_join, #add_pending_joins_if_needed, #apply_flat, #apply_flat_relational_condition, #condition_uses_different_database?, #get_foreign_key_from_relation, #get_through_reflection, #handle_flat_cross_database_condition, #handle_flat_relational_condition
Methods included from HasIcon
#category_icon_class, #category_icon_template, #has_icon?, #icon_class, #icon_container_class, #icon_template, #with_category_icon_class, #with_category_icon_template, #with_icon, #with_icon_class, #with_icon_container_class, #with_icon_template
#forced_index, #with_forced_index
#through_id_relationship, #with_through_id_relationship
#apply_count_refinement, #apply_date_refinement, #apply_refinements, #define_count_condition, #define_date_condition, #get_count_refinement_condition, #get_date_refinement_condition, #has_any_refinements?, #has_count_refinement?, #has_date_refinement?, #refine_by_count, #refine_by_date, #refine_by_filter, #refinements_allowed?, #refinements_to_array
#apply_relationship_attribute, #can_use_where_in_relationship_subquery?, #create_pending_has_many_through_subquery, #create_pending_wherein_subquery, #get_reflection_object, #group, #is_relationship_attribute?, #key_1, #key_2, #raw_attribute, #should_inverse_clause?, #with_attribute
Methods included from HasMeta
#meta, #with_meta
Instance Attribute Details
#value1 ⇒ Object
Returns the value of attribute value1.
16
17
18
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 16
def value1
@value1
end
|
#value2 ⇒ Object
Returns the value of attribute value2.
16
17
18
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 16
def value2
@value2
end
|
Instance Method Details
#allow_floats ⇒ Object
101
102
103
104
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 101
def allow_floats
@floats = true
self
end
|
#apply_clause_between(table, value1, value2) ⇒ Object
208
209
210
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 208
def apply_clause_between(table, value1, value2)
table.grouping(arel_attribute(table).between(value1..value2))
end
|
#apply_clause_doesnt_equal(table, value) ⇒ Object
188
189
190
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 188
def apply_clause_doesnt_equal(table, value)
table.grouping(arel_attribute(table).not_eq(value).or(arel_attribute(table).eq(nil)))
end
|
#apply_clause_equals(table, value) ⇒ Object
184
185
186
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 184
def apply_clause_equals(table, value)
table.grouping(arel_attribute(table).eq(value))
end
|
#apply_clause_greater_than(table, value) ⇒ Object
192
193
194
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 192
def apply_clause_greater_than(table, value)
table.grouping(arel_attribute(table).gt(value))
end
|
#apply_clause_greater_than_or_equal(table, value) ⇒ Object
196
197
198
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 196
def apply_clause_greater_than_or_equal(table, value)
table.grouping(arel_attribute(table).gteq(value))
end
|
#apply_clause_less_than(table, value) ⇒ Object
200
201
202
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 200
def apply_clause_less_than(table, value)
table.grouping(arel_attribute(table).lt(value))
end
|
#apply_clause_less_than_or_equal(table, value) ⇒ Object
204
205
206
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 204
def apply_clause_less_than_or_equal(table, value)
table.grouping(arel_attribute(table).lteq(value))
end
|
#apply_clause_not_between(table, value1, value2) ⇒ Object
212
213
214
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 212
def apply_clause_not_between(table, value1, value2)
table.grouping(arel_attribute(table).not_between(value1..value2))
end
|
#apply_clause_not_set(table) ⇒ Object
220
221
222
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 220
def apply_clause_not_set(table)
table.grouping(arel_attribute(table).eq(nil))
end
|
#apply_clause_set(table) ⇒ Object
216
217
218
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 216
def apply_clause_set(table)
table.grouping(arel_attribute(table).not_eq(nil))
end
|
#apply_condition(input, table, _inverse_clause) ⇒ Object
TODO Refactor to remove input here
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 111
def apply_condition(input, table, _inverse_clause)
case clause
when CLAUSE_EQUALS
apply_clause_equals(table, value1)
when CLAUSE_DOESNT_EQUAL
apply_clause_doesnt_equal(table, value1)
when CLAUSE_GREATER_THAN
apply_clause_greater_than(table, value1)
when CLAUSE_GREATER_THAN_OR_EQUAL
apply_clause_greater_than_or_equal(table, value1)
when CLAUSE_LESS_THAN
apply_clause_less_than(table, value1)
when CLAUSE_LESS_THAN_OR_EQUAL
apply_clause_less_than_or_equal(table, value1)
when CLAUSE_BETWEEN
apply_clause_between(table, value1, value2)
when CLAUSE_NOT_BETWEEN
apply_clause_not_between(table, value1, value2)
when CLAUSE_SET
apply_clause_set(table)
when CLAUSE_NOT_SET
apply_clause_not_set(table)
end
end
|
#boot ⇒ Object
34
35
36
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 34
def boot
@floats = false
end
|
#clauses ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 77
def clauses
[
Clause.new(CLAUSE_EQUALS, I18n.t("#{I18N_PREFIX}is")).requires_inputs(["value1"]),
Clause.new(CLAUSE_DOESNT_EQUAL, I18n.t("#{I18N_PREFIX}is_not")).requires_inputs(["value1"]),
Clause.new(CLAUSE_GREATER_THAN, I18n.t("#{I18N_PREFIX}is_gt")).requires_inputs(["value1"]),
Clause.new(CLAUSE_GREATER_THAN_OR_EQUAL, I18n.t("#{I18N_PREFIX}is_gtteq")).requires_inputs(["value1"]),
Clause.new(CLAUSE_LESS_THAN, I18n.t("#{I18N_PREFIX}is_lt")).requires_inputs(["value1"]),
Clause.new(CLAUSE_LESS_THAN_OR_EQUAL, I18n.t("#{I18N_PREFIX}is_lteq")).requires_inputs(["value1"]),
Clause.new(CLAUSE_BETWEEN, I18n.t("#{I18N_PREFIX}is_between")).requires_inputs(["value1", "value2"]),
Clause.new(CLAUSE_NOT_BETWEEN, I18n.t("#{I18N_PREFIX}is_not_between")).requires_inputs(["value1", "value2"]),
Clause.new(CLAUSE_SET, I18n.t("#{I18N_PREFIX}is_set")),
Clause.new(CLAUSE_NOT_SET, I18n.t("#{I18N_PREFIX}is_not_set")),
]
end
|
#component ⇒ Object
43
44
45
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 43
def component
"numeric-condition"
end
|
#floats_not_allowed? ⇒ Boolean
106
107
108
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 106
def floats_not_allowed?
!@floats
end
|
#human_readable(input) ⇒ Object
#human_readable_value(input) ⇒ Object
38
39
40
41
|
# File 'app/models/refine/conditions/numeric_condition.rb', line 38
def set_input_parameters(input)
@value1 = input[:value1]
@value2 = input[:value2]
end
|