Module: DVLA::Kaping::QueryTerm

Included in:
Query
Defined in:
lib/dvla/kaping/query_term.rb

Instance Method Summary collapse

Instance Method Details

#between(field, *args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dvla/kaping/query_term.rb', line 61

def between(field, *args)
  fragment = case args
             in [Range]
               { gte: args.first.first, lte: args.first.last }
             in [String, String]
               { gte: args.first, lte: args.last }
             in [Hash]
               args.first
             else
               raise ArgumentError, "Expected either a range or a upper and lower bounds, got #{args}"
             end
  current_operation << {
    range: { "#{field}": fragment },
  }
  self
end

#current_operationObject



78
79
80
# File 'lib/dvla/kaping/query_term.rb', line 78

def current_operation
  operations[last_operation]
end

#current_params(value) ⇒ Object



82
83
84
85
86
# File 'lib/dvla/kaping/query_term.rb', line 82

def current_params(value)
  if value.key?(Constants::ALLOWED_PARAMS)
    operations.merge!(value)
  end
end

#exists(field, value) ⇒ Object



26
27
28
29
30
31
# File 'lib/dvla/kaping/query_term.rb', line 26

def exists(field, value)
  current_operation << {
    exists: { "#{field}": value },
  }
  self
end

#match(field, value) ⇒ Object



19
20
21
22
23
24
# File 'lib/dvla/kaping/query_term.rb', line 19

def match(field, value)
  current_operation << {
    match: { "#{field}": value },
  }
  self
end

#match_phrase(field, value, **kwargs) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/dvla/kaping/query_term.rb', line 11

def match_phrase(field, value, **kwargs)
  current_operation << {
    match_phrase: { "#{field}": value },
  }
  current_params(kwargs)
  self
end

#prefix(field, value) ⇒ Object



47
48
49
50
51
52
# File 'lib/dvla/kaping/query_term.rb', line 47

def prefix(field, value)
  current_operation << {
    prefix: { "#{field}": value },
  }
  self
end

#regex(field, value) ⇒ Object



54
55
56
57
58
59
# File 'lib/dvla/kaping/query_term.rb', line 54

def regex(field, value)
  current_operation << {
    regex: { "#{field}": value },
  }
  self
end

#term(field, value) ⇒ Object



40
41
42
43
44
45
# File 'lib/dvla/kaping/query_term.rb', line 40

def term(field, value)
  current_operation << {
    term: { "#{field}": value },
  }
  self
end

#wildcard(field, value) ⇒ Object



33
34
35
36
37
38
# File 'lib/dvla/kaping/query_term.rb', line 33

def wildcard(field, value)
  current_operation << {
    wildcard: { "#{field}": value },
  }
  self
end