Class: Floe::Workflow::ChoiceRule::Data

Inherits:
Floe::Workflow::ChoiceRule show all
Defined in:
lib/floe/workflow/choice_rule/data.rb

Constant Summary collapse

TYPES =
["String", "Numeric", "Boolean", "Timestamp", "Present", "Null"].freeze
COMPARES =
["Equals", "LessThan", "GreaterThan", "LessThanEquals", "GreaterThanEquals", "Matches"].freeze
TYPE_CHECK =

e.g.: (Is)(String), (Is)(Present)

/^(Is)(#{TYPES.join("|")})$/.freeze
OPERATION =

e.g.: (String)(LessThan)(Path), (Numeric)(GreaterThanEquals)()

/^(#{(TYPES - %w[Null Present]).join("|")})(#{COMPARES.join("|")})(Path)?$/.freeze

Instance Attribute Summary collapse

Attributes inherited from Floe::Workflow::ChoiceRule

#children, #name, #next, #payload

Instance Method Summary collapse

Methods inherited from Floe::Workflow::ChoiceRule

build, build_children

Methods included from ValidationMixin

included, #invalid_field_error!, #missing_field_error!, #parser_error!, #runtime_field_error!, #workflow_state?, #wrap_parser_error

Constructor Details

#initialize(_workflow, _name, payload) ⇒ Data

Returns a new instance of Data.



16
17
18
19
20
21
# File 'lib/floe/workflow/choice_rule/data.rb', line 16

def initialize(_workflow, _name, payload)
  super

  @variable = parse_path("Variable")
  parse_compare_key
end

Instance Attribute Details

#compare_keyObject (readonly)

Returns the value of attribute compare_key.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def compare_key
  @compare_key
end

#compare_predicateObject (readonly)

Returns the value of attribute compare_predicate.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def compare_predicate
  @compare_predicate
end

#operationObject (readonly)

Returns the value of attribute operation.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def operation
  @operation
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def type
  @type
end

#variableObject (readonly)

Returns the value of attribute variable.



14
15
16
# File 'lib/floe/workflow/choice_rule/data.rb', line 14

def variable
  @variable
end

Instance Method Details

#true?(context, input) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/floe/workflow/choice_rule/data.rb', line 23

def true?(context, input)
  return presence_check(context, input) if compare_key == "IsPresent"

  lhs = variable_value(context, input)
  rhs = compare_value(context, input)
  send(operation, lhs, rhs)
end