Class: DynamicFieldsets::Dependency

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dynamic_fieldsets/dependency.rb

Overview

Logical atom for dealing with dependency clauses

Author:

  • John “hex” Carter

Constant Summary collapse

RELATIONSHIP_LIST =
["equals","not equals","includes","not includes","blank","not blank"]

Instance Method Summary collapse

Instance Method Details

#evaluate(input_hash) ⇒ Object

Looks through the input_hash for the fieldset_child that matches the one belonging to this dependency and compares the values through process_relationship



60
61
62
63
64
65
66
67
# File 'app/models/dynamic_fieldsets/dependency.rb', line 60

def evaluate(input_hash)
  input_value = input_hash[self.fieldset_child_id]
  unless input_value.nil?
    return self.process_relationship(input_value)
  else
    return false
  end
end

#process_relationship(input_value) ⇒ Object

Returns true or false based on whether the value pushed in matches the logical relationship between it and the dependency’s value



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/dynamic_fieldsets/dependency.rb', line 36

def process_relationship(input_value)
  case self.relationship
  when "equals" 
    return self.value == input_value
  when "not equals"
    return self.value != input_value
  when "includes"
    return input_value.include?(self.value)
  when "not includes"
    return !input_value.include?(self.value)
  when "blank"
    return input_value == ""
  when "not blank"
    return input_value != ""
  else
    return false
  end
end

#relationship_listObject

Returns a full list of the options for relationship_list



27
28
29
# File 'app/models/dynamic_fieldsets/dependency.rb', line 27

def relationship_list
  return RELATIONSHIP_LIST
end

#to_hashObject



69
70
71
# File 'app/models/dynamic_fieldsets/dependency.rb', line 69

def to_hash
  return { "id" => self.id, "fieldset_child_id" => self.fieldset_child_id, "value" => self.value, "relationship" => self.relationship, "dependency_clause_id" => self.dependency_clause_id }
end