class TransactionQL::Filter

Attributes

name[R]
query[R]

Public Class Methods

new(name, &block) click to toggle source
# File lib/transaction_ql/filter.rb, line 7
def initialize(name, &block)
  @name = name
  @query = All.new []

  @block_depth = 0
  @last_blocks = []
  @timeframe = []

  instance_eval(&block)
end

Public Instance Methods

any(&block) click to toggle source
# File lib/transaction_ql/filter.rb, line 52
def any(&block)
  last_block = process_inner(&block)
  add_expression Any.new(last_block)
end
equal(column, other) click to toggle source
# File lib/transaction_ql/filter.rb, line 34
def equal(column, other)
  add_expression Equal.new(column, other)
end
greater(column, other) click to toggle source
# File lib/transaction_ql/filter.rb, line 26
def greater(column, other)
  add_expression Greater.new(column, other)
end
greater_eq(column, other) click to toggle source
# File lib/transaction_ql/filter.rb, line 38
def greater_eq(column, other)
  add_expression Any.new [
    Greater.new(column, other),
    Equal.new(column, other)
  ]
end
invert(&block) click to toggle source
# File lib/transaction_ql/filter.rb, line 57
def invert(&block)
  last_block = process_inner(&block)
  add_expression Not.new(last_block)
end
match(column, regex) click to toggle source
# File lib/transaction_ql/filter.rb, line 22
def match(column, regex)
  add_expression Match.new(column, regex)
end
matches?(hash) click to toggle source
# File lib/transaction_ql/filter.rb, line 18
def matches?(hash)
  @query.matches? hash
end
smaller(column, other) click to toggle source
# File lib/transaction_ql/filter.rb, line 30
def smaller(column, other)
  add_expression Smaller.new(column, other)
end
smaller_eq(column, other) click to toggle source
# File lib/transaction_ql/filter.rb, line 45
def smaller_eq(column, other)
  add_expression Any.new [
    Smaller.new(column, other),
    Equal.new(column, other)
  ]
end

Private Instance Methods

add_expression(expression) click to toggle source
# File lib/transaction_ql/filter.rb, line 72
def add_expression(expression)
  if @block_depth > 0
    @last_blocks[-1] << expression
  else
    @query.expressions << expression
  end
end
process_inner(&block) click to toggle source
# File lib/transaction_ql/filter.rb, line 64
def process_inner(&block)
  @last_blocks.push []
  @block_depth += 1
  instance_eval(&block)
  @block_depth -= 1
  @last_blocks.pop
end