Class: FlowEngine::Rules::Contains
- Defined in:
- lib/flowengine/rules/contains.rb
Overview
Rule: the answer for the given field (as an array) includes the given value. Used for multi-select steps (e.g. "BusinessOwnership in earnings").
Instance Attribute Summary collapse
-
#field ⇒ Symbol
readonly
answer key (step id).
-
#value ⇒ Object
readonly
value that must be present in the array.
Instance Method Summary collapse
-
#evaluate(answers) ⇒ Boolean
True if answers (as array) includes value.
-
#initialize(field, value) ⇒ Contains
constructor
A new instance of Contains.
-
#to_s ⇒ String
E.g.
Constructor Details
#initialize(field, value) ⇒ Contains
Returns a new instance of Contains.
15 16 17 18 19 20 |
# File 'lib/flowengine/rules/contains.rb', line 15 def initialize(field, value) super() @field = field @value = value freeze end |
Instance Attribute Details
#field ⇒ Symbol (readonly)
answer key (step id)
10 11 12 |
# File 'lib/flowengine/rules/contains.rb', line 10 def field @field end |
#value ⇒ Object (readonly)
value that must be present in the array
10 11 12 |
# File 'lib/flowengine/rules/contains.rb', line 10 def value @value end |
Instance Method Details
#evaluate(answers) ⇒ Boolean
Returns true if answers (as array) includes value.
24 25 26 |
# File 'lib/flowengine/rules/contains.rb', line 24 def evaluate(answers) Array(answers[field]).include?(value) end |
#to_s ⇒ String
Returns e.g. "BusinessOwnership in earnings".
29 30 31 |
# File 'lib/flowengine/rules/contains.rb', line 29 def to_s "#{value} in #{field}" end |