Class: Udat::Collection::UnorderedWrapper
Overview
Internally used wrapper class for Udat::Node’s, to lookup Udat::Collection’s in Hash’es, while ignoring the order of their content.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(content) ⇒ UnorderedWrapper
constructor
A new instance of UnorderedWrapper.
Constructor Details
#initialize(content) ⇒ UnorderedWrapper
Returns a new instance of UnorderedWrapper.
486 487 488 |
# File 'lib/udat.rb', line 486 def initialize(content) @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
489 490 491 |
# File 'lib/udat.rb', line 489 def content @content end |
Instance Method Details
#==(other) ⇒ Object
532 533 534 |
# File 'lib/udat.rb', line 532 def ==(other) self.eql? other end |
#eql?(other) ⇒ Boolean
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/udat.rb', line 502 def eql?(other) return false unless self.class == other.class unless self.content.kind_of? Node and other.content.kind_of? Node return self.content.eql?(other.content) end if self.content.class == other.content.class self.content.tag == other.content.tag if self.content.kind_of? Collection 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 |
#hash ⇒ Object
490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/udat.rb', line 490 def hash if content.kind_of? Collection 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 |