Class: FlowEngine::Rules::Contains

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ Contains

Returns a new instance of Contains.

Parameters:

  • field (Symbol) —

    answer key

  • value (Object) —

    value to check for



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)

Returns:

  • (Symbol) —

    the current value of field



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

Returns:

  • (Object) —

    the current value of value



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.

Parameters:

  • answers (Hash) —

    current answers

Returns:

  • (Boolean) —

    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".

Returns:

  • (String) —

    e.g. "BusinessOwnership in earnings"



29
30
31
# File 'lib/flowengine/rules/contains.rb', line 29

def to_s
  "#{value} in #{field}"
end