| Class | Aquarium::Finders::FinderResult |
| In: |
lib/aquarium/finders/finder_result.rb
|
| Parent: | Object |
Wraps hashes that hold the results of various *Finder utilities. The not_matched method returns specified inputs that did not result in a successful find.
| NIL_OBJECT | = | FinderResult.new unless const_defined?(:NIL_OBJECT) |
| matched | [RW] | |
| not_matched | [RW] |
# File lib/aquarium/finders/finder_result.rb, line 31
31: def initialize hash = {}
32: @matched = convert_hash_values_to_sets(hash.reject {|key, value| key.eql?(:not_matched)})
33: @not_matched = convert_hash_values_to_sets(make_hash(hash[:not_matched]) {|x| Set.new} || {})
34: end
# File lib/aquarium/finders/finder_result.rb, line 48
48: def << other_result
49: append_matched other_result.matched
50: append_not_matched other_result.not_matched
51: self
52: end
"And" two results together
# File lib/aquarium/finders/finder_result.rb, line 70
70: def and other_result
71: result = dup
72: result.matched = hash_intersection(matched, other_result.matched)
73: result.not_matched = hash_intersection(not_matched, other_result.not_matched)
74: result
75: end
# File lib/aquarium/finders/finder_result.rb, line 89
89: def append_matched other_hash = {}
90: @matched = convert_hash_values_to_sets hash_union(matched, other_hash)
91: end
# File lib/aquarium/finders/finder_result.rb, line 93
93: def append_not_matched other_hash = {}
94: @not_matched = convert_hash_values_to_sets hash_union(not_matched, other_hash)
95: @not_matched.each_key {|key| purge_matched key}
96: end
Were there no matches?
# File lib/aquarium/finders/finder_result.rb, line 112
112: def empty?
113: matched.empty?
114: end
# File lib/aquarium/finders/finder_result.rb, line 98
98: def eql? other
99: object_id == other.object_id ||
100: (matched == other.matched and not_matched == other.not_matched)
101: end
# File lib/aquarium/finders/finder_result.rb, line 105
105: def inspect
106: "FinderResult: {matched: #{matched.inspect}, not_matched: #{not_matched.inspect}}"
107: end
Convenience method to get the keys for the matches.
# File lib/aquarium/finders/finder_result.rb, line 39
39: def matched_keys
40: @matched.keys
41: end
# File lib/aquarium/finders/finder_result.rb, line 80
80: def minus other_result
81: result = dup
82: result.matched = matched - other_result.matched
83: result.not_matched = not_matched - other_result.not_matched
84: result
85: end
Convenience method to get the keys for the items that did not result in matches.
# File lib/aquarium/finders/finder_result.rb, line 44
44: def not_matched_keys
45: @not_matched.keys
46: end