Class: TransactionQL::NumericExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/transaction_ql/expressions.rb

Direct Known Subclasses

Equal, Greater, Smaller

Instance Method Summary collapse

Constructor Details

#initialize(column, other, operator) ⇒ NumericExpression

Returns a new instance of NumericExpression.



9
10
11
12
13
# File 'lib/transaction_ql/expressions.rb', line 9

def initialize(column, other, operator)
  @column = column
  @other = other
  @operator = operator
end

Instance Method Details

#matches?(hash) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/transaction_ql/expressions.rb', line 15

def matches?(hash)
  case @other
  when Numeric
    hash.fetch(@column).send @operator, @other
  when String
    if !hash[@other].is_a? Numeric
      raise "Column `#{@other}` is not numeric!"
    end
    hash.fetch(@column).send @operator, hash.fetch(@other)
  else
    raise 'Unsupported right hand type.'
  end
end