Class: Filterism::ParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/filterism/parsers/params_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParamsParser



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/filterism/parsers/params_parser.rb', line 4

def initialize
  @comparators = {
    'equal_to' => '=',
    'not_equal_to' => '!=',

    'greater_than' => '>',
    'gt' => '>',
    'after' => '>',
    'greater_than_or_equal_to' => '>=',
    'gtet' => '>=',

    'less_than' => '<',
    'lt' => '<',
    'before' => '<',
    'less_than_or_equal_to' => '<=',
    'ltet' => '<=',

    'like' => 'LIKE',

    'in' => 'IN'
  }
end

Instance Attribute Details

#comparatorsObject

Returns the value of attribute comparators.



3
4
5
# File 'lib/filterism/parsers/params_parser.rb', line 3

def comparators
  @comparators
end

Instance Method Details

#add_comparator(comparator) ⇒ Object



43
44
45
# File 'lib/filterism/parsers/params_parser.rb', line 43

def add_comparator(comparator)
  @comparators = @comparators.merge(comparator)
end

#delete_comparator(comparator_key) ⇒ Object



47
48
49
# File 'lib/filterism/parsers/params_parser.rb', line 47

def delete_comparator(comparator_key)
  @comparators.delete(comparator_key)
end

#parse(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/filterism/parsers/params_parser.rb', line 27

def parse(params)
  conditions = []
  params.each do |key, value|
    keysplit = key.to_s.split('_is_')
    if @comparators.keys.include?(keysplit[1])
      conditions <<
      {
        key: keysplit[0],
        comparator: @comparators[keysplit[1]],
        value: value
      }
    end
  end
  return conditions
end