Class: FlowEngine::Rules::GreaterThan

Inherits:
Base
  • Object
show all
Defined in:
lib/flowengine/rules/greater_than.rb

Overview

Rule: the answer for the given field (coerced to integer) is greater than the threshold.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ GreaterThan

Returns a new instance of GreaterThan.

Parameters:

  • answer key

  • threshold



14
15
16
17
18
19
# File 'lib/flowengine/rules/greater_than.rb', line 14

def initialize(field, value)
  super()
  @field = field
  @value = value
  freeze
end

Instance Attribute Details

#field ⇒ Symbol (readonly)

answer key

Returns:

  • the current value of field



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

def field
  @field
end

#value ⇒ Integer (readonly)

threshold

Returns:

  • the current value of value



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

def value
  @value
end

Instance Method Details

#evaluate(answers) ⇒ Boolean

Returns true if answers.to_i > value.

Parameters:

  • current answers (field value is coerced with to_i)

Returns:



23
24
25
# File 'lib/flowengine/rules/greater_than.rb', line 23

def evaluate(answers)
  answers[field].to_i > value
end

#to_s ⇒ String

Returns e.g. "business_income > 100000".

Returns:

  • e.g. "business_income > 100000"



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

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