Class: Safer::HashProtocol::All

Inherits:
Compound show all
Defined in:
lib/safer/hashprotocol.rb

Overview

Check that all of a set of Safer::HashProtocol objects match a Hash.

Instance Method Summary collapse

Methods inherited from Compound

#self

Methods inherited from Base

#self

Constructor Details

#initialize(*list) ⇒ All

The description for this object will be the descriptions for each argument, separated by “ AND ”.



221
222
223
# File 'lib/safer/hashprotocol.rb', line 221

def initialize(*list)
  super(" AND ", *list)
end

Instance Method Details

#===(h) ⇒ Object

Check if all elements from the list argument to initialize match Hash h.



228
229
230
# File 'lib/safer/hashprotocol.rb', line 228

def ===(h)
  self.list.all? do |el| el === h end
end

#match(h, remaining) ⇒ Object

Check if all elements from the list argument to initialize match Hash h. If they do, remaining will be updated to remove all matching elements from list. If not all elements match, remaining will be unmodified.



237
238
239
240
241
242
243
244
# File 'lib/safer/hashprotocol.rb', line 237

def match(h, remaining)
  nremaining = remaining.dup
  rval = self.list.all? do |el| el.match(h, nremaining) end
  if rval
    remaining.update(nremaining)
  end
  rval
end