Class: Ruleby::Core::MatchResult
- Inherits:
-
Object
- Object
- Ruleby::Core::MatchResult
- Defined in:
- lib/core/utils.rb
Overview
This class represents a partial match. It contains the variables, values, and some metadata about the match. For the most part, this metadata is used during conflict resolution.
Instance Attribute Summary collapse
-
#fact_hash ⇒ Object
Returns the value of attribute fact_hash.
-
#is_match ⇒ Object
Returns the value of attribute is_match.
-
#recency ⇒ Object
Returns the value of attribute recency.
-
#variables ⇒ Object
TODO this class needs to be cleaned up so that we don’t have a bunch of properties.
Instance Method Summary collapse
- #==(match) ⇒ Object
- #[](sym) ⇒ Object
- #[]=(sym, object) ⇒ Object
- #clear ⇒ Object
- #delete(tag) ⇒ Object
- #dup ⇒ Object
- #fact_ids ⇒ Object
-
#initialize(variables = Hash.new, is_match = false, fact_hash = {}, recency = []) ⇒ MatchResult
constructor
A new instance of MatchResult.
- #key?(m) ⇒ Boolean
- #keys ⇒ Object
- #merge(mr) ⇒ Object
- #merge!(mr) ⇒ Object
- #to_s ⇒ Object
- #update(mr) ⇒ Object
Constructor Details
#initialize(variables = Hash.new, is_match = false, fact_hash = {}, recency = []) ⇒ MatchResult
Returns a new instance of MatchResult.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/core/utils.rb', line 76 def initialize(variables=Hash.new,is_match=false,fact_hash={},recency=[]) @variables = variables # a list of recencies of the facts that this matchresult depends on. @recency = recency # notes where this match result is from a NotPattern or ObjectPattern # TODO this isn't really needed anymore. how can we get rid of it? @is_match = is_match # a hash of fact.ids that each tag corresponds to @fact_hash = fact_hash end |
Instance Attribute Details
#fact_hash ⇒ Object
Returns the value of attribute fact_hash.
73 74 75 |
# File 'lib/core/utils.rb', line 73 def fact_hash @fact_hash end |
#is_match ⇒ Object
Returns the value of attribute is_match.
72 73 74 |
# File 'lib/core/utils.rb', line 72 def is_match @is_match end |
#recency ⇒ Object
Returns the value of attribute recency.
74 75 76 |
# File 'lib/core/utils.rb', line 74 def recency @recency end |
#variables ⇒ Object
TODO this class needs to be cleaned up so that we don’t have a bunch of properties. Instead, maybe it sould have a list of facts.
71 72 73 |
# File 'lib/core/utils.rb', line 71 def variables @variables end |
Instance Method Details
#==(match) ⇒ Object
102 103 104 |
# File 'lib/core/utils.rb', line 102 def ==(match) return match != nil && @variables == match.variables && @is_match == match.is_match && @fact_hash == match.fact_hash end |
#[](sym) ⇒ Object
94 95 96 |
# File 'lib/core/utils.rb', line 94 def [](sym) return @variables[sym] end |
#[]=(sym, object) ⇒ Object
90 91 92 |
# File 'lib/core/utils.rb', line 90 def []=(sym, object) @variables[sym] = object end |
#clear ⇒ Object
144 145 146 147 148 |
# File 'lib/core/utils.rb', line 144 def clear @variables = {} @fact_hash = {} @recency = [] end |
#delete(tag) ⇒ Object
150 151 152 153 |
# File 'lib/core/utils.rb', line 150 def delete(tag) @variables.delete(tag) @fact_hash.delete(tag) end |
#dup ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/core/utils.rb', line 122 def dup dup_mr = MatchResult.new dup_mr.recency = @recency.clone dup_mr.is_match = @is_match dup_mr.variables = @variables.clone dup_mr.fact_hash = @fact_hash.clone return dup_mr end |
#fact_ids ⇒ Object
98 99 100 |
# File 'lib/core/utils.rb', line 98 def fact_ids return fact_hash.values.uniq end |
#key?(m) ⇒ Boolean
106 107 108 |
# File 'lib/core/utils.rb', line 106 def key?(m) return @variables.key?(m) end |
#keys ⇒ Object
110 111 112 |
# File 'lib/core/utils.rb', line 110 def keys return @variables.keys end |
#merge(mr) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/core/utils.rb', line 135 def merge(mr) new_mr = MatchResult.new new_mr.recency = @recency | mr.recency new_mr.is_match = mr.is_match new_mr.variables = @variables.merge mr.variables new_mr.fact_hash = @fact_hash.merge mr.fact_hash return new_mr end |
#merge!(mr) ⇒ Object
131 132 133 |
# File 'lib/core/utils.rb', line 131 def merge!(mr) return update(mr) end |
#to_s ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/core/utils.rb', line 155 def to_s s = '#MatchResult(' s = s + 'f)(' unless @is_match s = s + object_id.to_s+')(' @variables.each do |key,value| s += "#{key}=#{value}/#{@fact_hash[key]}, " end return s + ")" end |
#update(mr) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/core/utils.rb', line 114 def update(mr) @recency = @recency | mr.recency @is_match = mr.is_match @variables = @variables.update mr.variables @fact_hash = @fact_hash.update mr.fact_hash return self end |