Class: FlowEngine::Rules::LessThan
- Defined in:
- lib/flowengine/rules/less_than.rb
Overview
Rule: the answer for the given field (coerced to integer) is less than the threshold.
Instance Attribute Summary collapse
-
#field ⇒ Symbol
readonly
answer key.
-
#value ⇒ Integer
readonly
threshold.
Instance Method Summary collapse
-
#evaluate(answers) ⇒ Boolean
True if answers.to_i < value.
-
#initialize(field, value) ⇒ LessThan
constructor
A new instance of LessThan.
-
#to_s ⇒ String
E.g.
Constructor Details
#initialize(field, value) ⇒ LessThan
Returns a new instance of LessThan.
14 15 16 17 18 19 |
# File 'lib/flowengine/rules/less_than.rb', line 14 def initialize(field, value) super() @field = field @value = value freeze end |
Instance Attribute Details
#field ⇒ Symbol (readonly)
answer key
9 10 11 |
# File 'lib/flowengine/rules/less_than.rb', line 9 def field @field end |
#value ⇒ Integer (readonly)
threshold
9 10 11 |
# File 'lib/flowengine/rules/less_than.rb', line 9 def value @value end |
Instance Method Details
#evaluate(answers) ⇒ Boolean
Returns true if answers.to_i < value.
23 24 25 |
# File 'lib/flowengine/rules/less_than.rb', line 23 def evaluate(answers) answers[field].to_i < value end |
#to_s ⇒ String
Returns e.g. "age < 18".
28 29 30 |
# File 'lib/flowengine/rules/less_than.rb', line 28 def to_s "#{field} < #{value}" end |