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(pred_xml) ⇒ NumericalPredicate

Returns a new instance of NumericalPredicate.



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

def initialize(pred_xml)
  @field = pred_xml.xpath('@field').to_s.to_sym
  @value = Float(pred_xml.xpath('@value').to_s)
  @operator = pred_xml.xpath('@operator').to_s
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