Class: Rules::AttributeChange

Inherits:
Rule
  • Object
show all
Defined in:
lib/question_chain/models/rules/attribute_change.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rule

#ui_object_id

Class Method Details

.attributes_for_apiObject



7
8
9
# File 'lib/question_chain/models/rules/attribute_change.rb', line 7

def self.attributes_for_api
  %w(id fire_value _type affecting_ui_objects ui_object_id negate_value compare_text_value)
end

Instance Method Details

#fire!(value, ui_objects) ⇒ Object

Checks to determine the value and the fire_value if cool then the ui objects are updated depending on the affecting values

 @param [Array<Hash>] ui_objects

Parameters:

  • ui_object (UiObject)

    the ui object that this rul is observing

  • value (String)

    the value that the ui_object has



17
18
19
20
21
22
23
24
25
# File 'lib/question_chain/models/rules/attribute_change.rb', line 17

def fire!(value, ui_objects)
  if negate_value ? value != self.fire_value : value == self.fire_value
    affecting_ui_objects.each_pair do |key, value|
      if ui_object = ui_objects.detect{|ui| ui["id"] == key}
        ui_object["ui_attributes"].merge!(value)
      end
    end
  end
end