Class: DependencyCondition
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DependencyCondition
- Defined in:
- app/models/dependency_condition.rb
Constant Summary collapse
- OPERATORS =
Constants
%w(== != < > <= >=)
Class Method Summary collapse
-
.operators ⇒ Object
Class methods.
Instance Method Summary collapse
-
#as(type_symbol) ⇒ Object
Method that returns the dependency as a particular response_class type.
-
#evaluation_of(response_set) ⇒ Object
Evaluates the condition on the response_set.
-
#is_satisfied_by?(response) ⇒ Boolean
Checks to see if the response passed in satisfies the dependency condition.
-
#symbol_key ⇒ Object
Returns the rule key to be used in the subsitution string in the parent depenedency object.
-
#to_evaluation_hash(response_set) ⇒ Object
The hash used in the dependency parent object to evaluate its rule string.
Class Method Details
.operators ⇒ Object
Class methods
17 18 19 |
# File 'app/models/dependency_condition.rb', line 17 def self.operators OPERATORS end |
Instance Method Details
#as(type_symbol) ⇒ Object
Method that returns the dependency as a particular response_class type
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/dependency_condition.rb', line 49 def as(type_symbol) return case type_symbol.to_sym when :string self.string_value when :text self.text_value when :integer self.integer_value when :float self.float_value when :answer self.answer_id else self.answer_id end end |
#evaluation_of(response_set) ⇒ Object
Evaluates the condition on the response_set
22 23 24 25 |
# File 'app/models/dependency_condition.rb', line 22 def evaluation_of(response_set) response = response_set.find_response(self.answer_id) || false # turns out eval("nil and false") => nil so we need to return false if no response is found return(response and self.is_satisfied_by?(response)) end |
#is_satisfied_by?(response) ⇒ Boolean
Checks to see if the response passed in satisfies the dependency condition
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/dependency_condition.rb', line 28 def is_satisfied_by?(response) response_class = response.answer.response_class return case self.operator when "==" response.as(response_class) == self.as(response_class) when "!=" response.as(response_class) != self.as(response_class) when "<" response.as(response_class) < self.as(response_class) when ">" response.as(response_class) > self.as(response_class) when "<=" response.as(response_class) <= self.as(response_class) when ">=" response.as(response_class) >= self.as(response_class) else false end end |
#symbol_key ⇒ Object
Returns the rule key to be used in the subsitution string in the parent depenedency object
72 73 74 |
# File 'app/models/dependency_condition.rb', line 72 def symbol_key self.rule_key.to_sym end |
#to_evaluation_hash(response_set) ⇒ Object
The hash used in the dependency parent object to evaluate its rule string
67 68 69 |
# File 'app/models/dependency_condition.rb', line 67 def to_evaluation_hash(response_set) {self.symbol_key => self.evaluation_of(response_set)} end |