Class: NumericalPredicate

Inherits:
Object
  • Object
show all
Defined in:
lib/numerical_predicate.rb

Constant Summary collapse

GREATER_THAN =
'greaterThan'
LESS_OR_EQUAL =
'lessOrEqual'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ NumericalPredicate

Returns a new instance of NumericalPredicate.



8
9
10
11
12
# File 'lib/numerical_predicate.rb', line 8

def initialize(attributes)
  @field = attributes['field'].value.to_sym
  @value = Float(attributes['value'].value)
  @operator = attributes['operator'].value
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'lib/numerical_predicate.rb', line 6

def field
  @field
end

Instance Method Details

#true?(features) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/numerical_predicate.rb', line 14

def true?(features)
  curr_value = Float(features[@field])
  return curr_value > @value if @operator == GREATER_THAN
  curr_value < @value if @operator == LESS_OR_EQUAL
end