class Btrack::Query::Criteria

Attributes

criteria[R]
options[R]

Public Class Methods

default_granularity() click to toggle source
# File lib/btrack/query/criteria.rb, line 45
def default_granularity
  Config.default_granularity.is_a?(Range) ? Config.default_granularity.first : Array.wrap(Config.default_granularity).first
end
new(criteria, options={}) click to toggle source

initializes a new crieteria

# File lib/btrack/query/criteria.rb, line 11
def initialize(criteria, options={})
  @criteria = parse(criteria).freeze
  @options = options.freeze
end
where(*args) click to toggle source
# File lib/btrack/query/criteria.rb, line 41
def where(*args)
  Criteria.new *args
end

Public Instance Methods

&(criteria) click to toggle source

returns a new criteria object with the union of both criterias

# File lib/btrack/query/criteria.rb, line 22
def &(criteria)
  Criteria.new self.criteria + criteria.criteria, self.options.merge(criteria.options)
end
query() click to toggle source

delegate method

# File lib/btrack/query/criteria.rb, line 51
def query
  Query.new self
end
realize!() click to toggle source

make this criteria 'real' by extracting keys and args to be passed to redis lua script

# File lib/btrack/query/criteria.rb, line 27
def realize!
  prefix = "#{@options[:prefix]}:" if @options[:prefix]

  keys = @criteria.map do |c|
    cvalue = c.values.first
    (Helper.keys "#{prefix}#{c.keys.first}", TimeFrame.new(cvalue, c[:granularity] || (cvalue.granularity if cvalue.is_a? TimeFrame) || self.class.default_granularity)).flatten
  end

  [keys.flatten << @options[:id], keys.map(&:count)]
end
where(*args) click to toggle source

returns a new criteria object with the union of both criterias

# File lib/btrack/query/criteria.rb, line 17
def where(*args)
  self & Criteria.new(*args)
end

Private Instance Methods

parse(criteria) click to toggle source
# File lib/btrack/query/criteria.rb, line 57
def parse(criteria)
  criteria.is_a?(Array) ? criteria : criteria.map { |k, v| {k => v} }
end