Class: Plunk::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/plunk/helper.rb

Class Method Summary collapse

Class Method Details

.combine_subtrees(left, right, op) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/plunk/helper.rb', line 5

def self.combine_subtrees(left, right, op)
  if right[op]
    { op => [left] + right[op] }
  else
    { op => [left, right] }
  end
end

.filter_builder(filter) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/plunk/helper.rb', line 23

def self.filter_builder(filter)
  {
    query: {
      filtered: {
        filter: filter
      }
    }
  }
end

.indices_builder(list) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/plunk/helper.rb', line 63

def self.indices_builder(list)
  {
    indices: {
      indices: list
    }
  }
end

.limit_builder(limit) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/plunk/helper.rb', line 33

def self.limit_builder(limit)
  {
    limit: {
      value: limit
    }
  }
end

.query_builder(query_string) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/plunk/helper.rb', line 13

def self.query_builder(query_string)
  {
    query: {
      query_string: {
        query: query_string
      }
    }
  }
end

.range_builder(range_min, range_max) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/plunk/helper.rb', line 41

def self.range_builder(range_min, range_max)
  {
    range: {
      Plunk.timestamp_field => {
        gte: range_min,
        lte: range_max
      }
    }
  }
end

.regexp_builder(field, regexp, flags = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/plunk/helper.rb', line 52

def self.regexp_builder(field, regexp, flags=nil)
  {
    regexp: {
      field => {
        value: regexp,
        flags: flags || 'ALL'
      }
    }
  }
end

.time_query_to_timestamp(int_quantity, quantifier) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/plunk/helper.rb', line 71

def self.time_query_to_timestamp(int_quantity, quantifier)
  case quantifier
  when 's'
    int_quantity.seconds.ago
  when 'm'
    int_quantity.minutes.ago
  when 'h'
    int_quantity.hours.ago
  when 'd'
    int_quantity.days.ago
  when 'w'
    int_quantity.weeks.ago
  end
end

.timestamp_format(time) ⇒ Object



86
87
88
# File 'lib/plunk/helper.rb', line 86

def self.timestamp_format(time)
  time.utc.to_datetime.iso8601(3)
end