class Aquarium::Finders::FinderResult

FinderResult

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.

Constants

NIL_OBJECT

Attributes

matched[RW]
not_matched[RW]

Public Class Methods

new(hash = {}) click to toggle source
# 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

Public Instance Methods

&(other_result) click to toggle source
Alias for: and
-(other_result) click to toggle source
Alias for: minus
<<(other_result) click to toggle source
# 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
==(other) click to toggle source
Alias for: eql?
and(other_result) click to toggle source

“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
Also aliased as: intersection, &
append_matched(other_hash = {}) click to toggle source
# 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
append_not_matched(other_hash = {}) click to toggle source
# 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
empty?() click to toggle source

Were there no matches?

# File lib/aquarium/finders/finder_result.rb, line 112
def empty?
  matched.empty?
end
eql?(other) click to toggle source
# 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
Also aliased as: ==
inspect() click to toggle source
# File lib/aquarium/finders/finder_result.rb, line 105
def inspect 
  "FinderResult: {matched: #{matched.inspect}, not_matched: #{not_matched.inspect}}"
end
Also aliased as: to_s
intersection(other_result) click to toggle source
Alias for: and
matched_keys() click to toggle source

Convenience method to get the keys for the matches.

# File lib/aquarium/finders/finder_result.rb, line 39
def matched_keys
  @matched.keys
end
minus(other_result) click to toggle source
# 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
Also aliased as: -
not_matched_keys() click to toggle source

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(other_result) click to toggle source

“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
Also aliased as: union, |
to_s() click to toggle source
Alias for: inspect
union(other_result) click to toggle source
Alias for: or
|(other_result) click to toggle source
Alias for: or