Class: UdatCollection::UdatUnorderedWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/udat.rb

Overview

Internally used wrapper class for Udat objects, to lookup UdatCollection’s in Hash’es, while ignoring the order of their content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ UdatUnorderedWrapper

Returns a new instance of UdatUnorderedWrapper.



405
406
407
# File 'lib/udat.rb', line 405

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



408
409
410
# File 'lib/udat.rb', line 408

def content
  @content
end

Instance Method Details

#==(other) ⇒ Object



447
448
449
# File 'lib/udat.rb', line 447

def ==(other)
  self.eql? other
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/udat.rb', line 421

def eql?(other)
  return false unless self.class == other.class
  if self.content.class == other.content.class and
      self.content.tag == other.content.tag
    if self.content.kind_of? UdatCollection
      own_pairs = self.content.key_value_pairs
      other_pairs = other.content.key_value_pairs
      own_pairs.each do |own_pair|
        catch :found do
          other_pairs.each_index do |index|
            if own_pair.eql? other_pairs[index]
              other_pairs.delete_at index
              throw :found
            end
          end
          return false
        end
      end
      return true
    else
      return self.content.eql?(other.content)
    end
  else
    return false
  end
end

#hashObject



409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/udat.rb', line 409

def hash
  if content.kind_of? UdatCollection
    hash = 0
    content.key_value_pairs.each do |key, value|
      hash += key.hash
      hash += value.hash
    end
    return hash
  else
    return content.hash
  end
end