Class: ForestLiana::OperatorValueParser
- Inherits:
-
Object
- Object
- ForestLiana::OperatorValueParser
- Defined in:
- app/services/forest_liana/operator_value_parser.rb
Class Method Summary collapse
- .add_where(query, field, operator, value, resource) ⇒ Object
- .get_field_name(field, resource) ⇒ Object
- .parse(value) ⇒ Object
Class Method Details
.add_where(query, field, operator, value, resource) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/forest_liana/operator_value_parser.rb', line 32 def self.add_where(query, field, operator, value, resource) field_name = self.get_field_name(field, resource) operator_date_interval_parser = OperatorDateIntervalParser.new(value) if operator_date_interval_parser.is_interval_date_value() filter = operator_date_interval_parser.get_interval_date_filter() query = query.where("#{field_name} #{filter}") else # NOTICE: Set the integer value instead of a string if "enum" type if resource.defined_enums.has_key?(field) value = resource.defined_enums[field][value] end where = "#{field_name} #{operator}" where += " '#{value}'" if value query = query.where(where) end end |
.get_field_name(field, resource) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/services/forest_liana/operator_value_parser.rb', line 51 def self.get_field_name(field, resource) if field.split(':').size < 2 "\"#{resource.table_name}\".\"#{field}\"" else association = field.split(':')[0].pluralize "\"#{association}\".\"#{field.split(':')[1]}\"" end end |
.parse(value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/forest_liana/operator_value_parser.rb', line 4 def self.parse(value) operator = nil if value.first == '!' operator = '!=' value.slice!(0) elsif value.first == '>' operator = '>' value.slice!(0) elsif value.first == '<' operator = '<' value.slice!(0) elsif value.include?('*') operator = 'ILIKE' value.gsub!('*', '%') elsif value === '$present' operator = 'IS NOT NULL' value = nil elsif value === '$blank' operator = 'IS NULL' value = nil else operator = '=' end [operator, value] end |