Class: MetadataPresenter::EvaluateConditionals
- Inherits:
-
Object
- Object
- MetadataPresenter::EvaluateConditionals
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/metadata_presenter/evaluate_conditionals.rb
Instance Attribute Summary collapse
-
#flow ⇒ Object
Returns the value of attribute flow.
-
#service ⇒ Object
Returns the value of attribute service.
-
#user_data ⇒ Object
Returns the value of attribute user_data.
Instance Method Summary collapse
Instance Attribute Details
#flow ⇒ Object
Returns the value of attribute flow.
4 5 6 |
# File 'app/models/metadata_presenter/evaluate_conditionals.rb', line 4 def flow @flow end |
#service ⇒ Object
Returns the value of attribute service.
4 5 6 |
# File 'app/models/metadata_presenter/evaluate_conditionals.rb', line 4 def service @service end |
#user_data ⇒ Object
Returns the value of attribute user_data.
4 5 6 |
# File 'app/models/metadata_presenter/evaluate_conditionals.rb', line 4 def user_data @user_data end |
Instance Method Details
#page ⇒ Object
6 7 8 9 10 |
# File 'app/models/metadata_presenter/evaluate_conditionals.rb', line 6 def page evaluated_page_uuid = page_uuid || flow.default_next service.find_page_by_uuid(evaluated_page_uuid) end |
#page_uuid ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/metadata_presenter/evaluate_conditionals.rb', line 12 def page_uuid @results ||= conditionals.map do |conditional| evaluated_expressions = conditional.expressions.map do |expression| expression.service = service Operator.new( expression.operator ).evaluate( expression.field_label, user_data[expression.expression_component.id] ) end if conditional.type == 'or' && evaluated_expressions.any? conditional.next elsif evaluated_expressions.all? conditional.next end end @results.flatten.compact.first end |