Class: Inquirex::Rules::Contains
- Defined in:
- lib/inquirex/rules/contains.rb
Overview
Rule: the answer for the given field (as an array) includes the given value. Used for multi_enum steps (e.g. “Business in income_types”).
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(answers) ⇒ Object
-
#initialize(field, value) ⇒ Contains
constructor
A new instance of Contains.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(field, value) ⇒ Contains
Returns a new instance of Contains.
10 11 12 13 14 15 |
# File 'lib/inquirex/rules/contains.rb', line 10 def initialize(field, value) super() @field = field.to_sym @value = value freeze end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
8 9 10 |
# File 'lib/inquirex/rules/contains.rb', line 8 def field @field end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/inquirex/rules/contains.rb', line 8 def value @value end |
Class Method Details
.from_h(hash) ⇒ Object
29 30 31 32 33 |
# File 'lib/inquirex/rules/contains.rb', line 29 def self.from_h(hash) field = hash["field"] || hash[:field] value = hash["value"] || hash[:value] new(field, value) end |
Instance Method Details
#evaluate(answers) ⇒ Object
17 18 19 |
# File 'lib/inquirex/rules/contains.rb', line 17 def evaluate(answers) Array(answers[@field]).include?(@value) end |
#to_h ⇒ Object
21 22 23 |
# File 'lib/inquirex/rules/contains.rb', line 21 def to_h { "op" => "contains", "field" => @field.to_s, "value" => @value } end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/inquirex/rules/contains.rb', line 25 def to_s "#{@value} in #{@field}" end |