Class: SpotFeel::Dmn::Decision
- Inherits:
-
Object
- Object
- SpotFeel::Dmn::Decision
- Defined in:
- lib/spot_feel/dmn/decision.rb
Instance Attribute Summary collapse
-
#decision_table ⇒ Object
readonly
Returns the value of attribute decision_table.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#information_requirements ⇒ Object
readonly
Returns the value of attribute information_requirements.
-
#literal_expression ⇒ Object
readonly
Returns the value of attribute literal_expression.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #evaluate(variables = {}) ⇒ Object
-
#initialize(id:, name:, decision_table:, variable:, literal_expression:, information_requirements:) ⇒ Decision
constructor
A new instance of Decision.
- #required_decision_ids ⇒ Object
Constructor Details
#initialize(id:, name:, decision_table:, variable:, literal_expression:, information_requirements:) ⇒ Decision
Returns a new instance of Decision.
16 17 18 19 20 21 22 23 |
# File 'lib/spot_feel/dmn/decision.rb', line 16 def initialize(id:, name:, decision_table:, variable:, literal_expression:, information_requirements:) @id = id @name = name @decision_table = decision_table @variable = variable @literal_expression = literal_expression @information_requirements = information_requirements end |
Instance Attribute Details
#decision_table ⇒ Object (readonly)
Returns the value of attribute decision_table.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def decision_table @decision_table end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def id @id end |
#information_requirements ⇒ Object (readonly)
Returns the value of attribute information_requirements.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def information_requirements @information_requirements end |
#literal_expression ⇒ Object (readonly)
Returns the value of attribute literal_expression.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def literal_expression @literal_expression end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def name @name end |
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
6 7 8 |
# File 'lib/spot_feel/dmn/decision.rb', line 6 def variable @variable end |
Class Method Details
.from_json(json) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/spot_feel/dmn/decision.rb', line 8 def self.from_json(json) information_requirements = Array.wrap(json[:information_requirement]).map { |ir| InformationRequirement.from_json(ir) } if json[:information_requirement] decision_table = DecisionTable.from_json(json[:decision_table]) if json[:decision_table] literal_expression = LiteralExpression.from_json(json[:literal_expression]) if json[:literal_expression] variable = Variable.from_json(json[:variable]) if json[:variable] Decision.new(id: json[:id], name: json[:name], decision_table:, variable:, literal_expression:, information_requirements:) end |
Instance Method Details
#as_json ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spot_feel/dmn/decision.rb', line 38 def as_json { id: id, name: name, decision_table: decision_table.as_json, variable: variable.as_json, literal_expression: literal_expression.as_json, information_requirements: information_requirements&.map(&:as_json), } end |
#evaluate(variables = {}) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/spot_feel/dmn/decision.rb', line 25 def evaluate(variables = {}) if literal_expression.present? result = literal_expression.evaluate(variables) variable.present? ? { variable.name => result } : result elsif decision_table.present? decision_table.evaluate(variables) end end |
#required_decision_ids ⇒ Object
34 35 36 |
# File 'lib/spot_feel/dmn/decision.rb', line 34 def required_decision_ids information_requirements&.map(&:required_decision_id) end |