Class: Extract::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/src/extract/expression.rb

Instance Method Summary collapse

Constructor Details

#initialize(expression, hash) ⇒ Expression

Returns a new instance of Expression.



5
6
7
8
# File 'lib/src/extract/expression.rb', line 5

def initialize(expression, hash)
  @expression = expression
  @hash = hash
end

Instance Method Details

#evaluateObject



10
11
12
13
14
15
# File 'lib/src/extract/expression.rb', line 10

def evaluate
  keys = Regexp.union(hash.keys.map(&:to_s))
  condition = expression.gsub(keys, hash.stringify_keys)

  eval(condition)
end