Class Aquarium::Finders::FinderResult
In: lib/aquarium/finders/finder_result.rb
Parent: Object

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.

Methods

&   -   <<   ==   and   append_matched   append_not_matched   empty?   eql?   inspect   intersection   matched_keys   minus   new   not_matched_keys   or   to_s   union   |  

Included Modules

Aquarium::Utils::HashUtils Aquarium::Utils::SetUtils

Constants

NIL_OBJECT = FinderResult.new unless const_defined?(:NIL_OBJECT)

Attributes

matched  [RW] 
not_matched  [RW] 

Public Class methods

[Source]

    # 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

Public Instance methods

&(other_result)

Alias for and

-(other_result)

Alias for minus

[Source]

    # 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
==(other)

Alias for eql?

"And" two results together

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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?

[Source]

     # File lib/aquarium/finders/finder_result.rb, line 112
112:       def empty?
113:         matched.empty?
114:       end

[Source]

     # 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

[Source]

     # File lib/aquarium/finders/finder_result.rb, line 105
105:       def inspect 
106:         "FinderResult: {matched: #{matched.inspect}, not_matched: #{not_matched.inspect}}"
107:       end
intersection(other_result)

Alias for and

Convenience method to get the keys for the matches.

[Source]

    # File lib/aquarium/finders/finder_result.rb, line 39
39:       def matched_keys
40:         @matched.keys
41:       end

[Source]

    # 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.

[Source]

    # File lib/aquarium/finders/finder_result.rb, line 44
44:       def not_matched_keys
45:         @not_matched.keys
46:       end

"Or" two results together

[Source]

    # File lib/aquarium/finders/finder_result.rb, line 59
59:       def or other_result
60:         result = dup
61:         result.matched     = hash_union(matched,     other_result.matched)
62:         result.not_matched = hash_union(not_matched, other_result.not_matched)
63:         result
64:       end
to_s()

Alias for inspect

union(other_result)

Alias for or

|(other_result)

Alias for or

[Validate]