Class: FlowEngine::Rules::LessThan

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

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ LessThan

Returns a new instance of LessThan.

Parameters:

  • field (Symbol) —

    answer key

  • value (Integer) —

    threshold



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

Returns:

  • (Symbol) —

    the current value of field



9
10
11
# File 'lib/flowengine/rules/less_than.rb', line 9

def field
  @field
end

#value ⇒ Integer (readonly)

threshold

Returns:

  • (Integer) —

    the current value of value



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.

Parameters:

  • answers (Hash) —

    current answers (field value is coerced with to_i)

Returns:

  • (Boolean) —

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

Returns:

  • (String) —

    e.g. "age < 18"



28
29
30
# File 'lib/flowengine/rules/less_than.rb', line 28

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