Class: Holoserve::Tool::Hash::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/holoserve/tool/hash/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, subset) ⇒ Matcher

Returns a new instance of Matcher.



7
8
9
# File 'lib/holoserve/tool/hash/matcher.rb', line 7

def initialize(hash, subset)
  @hash, @subset = hash, subset
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



4
5
6
# File 'lib/holoserve/tool/hash/matcher.rb', line 4

def hash
  @hash
end

#subsetObject

Returns the value of attribute subset.



5
6
7
# File 'lib/holoserve/tool/hash/matcher.rb', line 5

def subset
  @subset
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/holoserve/tool/hash/matcher.rb', line 11

def match?
  return false if @hash.length < @subset.length
  @subset.each do |key, value|
    if @hash.has_key?(key)
      return false unless match_value?(@hash[key], value)
    else
      return false
    end
  end
  true
end