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.
# File lib/aquarium/finders/finder_result.rb, line 31 def initialize hash = {} @matched = convert_hash_values_to_sets(hash.reject {|key, value| key.eql?(:not_matched)}) @not_matched = convert_hash_values_to_sets(make_hash(hash[:not_matched]) {|x| Set.new} || {}) end
# File lib/aquarium/finders/finder_result.rb, line 48 def << other_result append_matched other_result.matched append_not_matched other_result.not_matched self end
“And” two results together
# File lib/aquarium/finders/finder_result.rb, line 70 def and other_result result = dup result.matched = hash_intersection(matched, other_result.matched) result.not_matched = hash_intersection(not_matched, other_result.not_matched) result end
# File lib/aquarium/finders/finder_result.rb, line 89 def append_matched other_hash = {} @matched = convert_hash_values_to_sets hash_union(matched, other_hash) end
# File lib/aquarium/finders/finder_result.rb, line 93 def append_not_matched other_hash = {} @not_matched = convert_hash_values_to_sets hash_union(not_matched, other_hash) @not_matched.each_key {|key| purge_matched key} end
Were there no matches?
# File lib/aquarium/finders/finder_result.rb, line 112 def empty? matched.empty? end
# File lib/aquarium/finders/finder_result.rb, line 98 def eql? other object_id == other.object_id || (matched == other.matched and not_matched == other.not_matched) end
# File lib/aquarium/finders/finder_result.rb, line 105 def inspect "FinderResult: {matched: #{matched.inspect}, not_matched: #{not_matched.inspect}}" end
Convenience method to get the keys for the matches.
# File lib/aquarium/finders/finder_result.rb, line 39 def matched_keys @matched.keys end
# File lib/aquarium/finders/finder_result.rb, line 80 def minus other_result result = dup result.matched = matched - other_result.matched result.not_matched = not_matched - other_result.not_matched result 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 def not_matched_keys @not_matched.keys end
“Or” two results together
# File lib/aquarium/finders/finder_result.rb, line 59 def or other_result result = dup result.matched = hash_union(matched, other_result.matched) result.not_matched = hash_union(not_matched, other_result.not_matched) result end