Class: NumericalPredicate
- Inherits:
-
Object
- Object
- NumericalPredicate
- Defined in:
- lib/numerical_predicate.rb
Constant Summary collapse
- GREATER_THAN =
'greaterThan'- LESS_OR_EQUAL =
'lessOrEqual'
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ NumericalPredicate
constructor
A new instance of NumericalPredicate.
- #true?(features) ⇒ Boolean
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
#field ⇒ Object (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
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 |