class Plunk::Helper

Public Class Methods

combine_subtrees(left, right, op) click to toggle source
# 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) click to toggle source
# File lib/plunk/helper.rb, line 23
def self.filter_builder(filter)
  {
    query: {
      filtered: {
        filter: filter
      }
    }
  }
end
indices_builder(list) click to toggle source
# File lib/plunk/helper.rb, line 63
def self.indices_builder(list)
  {
    indices: {
      indices: list
    }
  }
end
limit_builder(limit) click to toggle source
# File lib/plunk/helper.rb, line 33
def self.limit_builder(limit)
  {
    limit: {
      value: limit
    }
  }
end
query_builder(query_string) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/plunk/helper.rb, line 86
def self.timestamp_format(time)
  time.utc.to_datetime.iso8601(3)
end