Class: RexleDiff::HashedDoc
- Inherits:
-
Object
- Object
- RexleDiff::HashedDoc
- Defined in:
- lib/rexle-diff.rb
Instance Method Summary collapse
- #hash(element) ⇒ Object
- #hashit(node) ⇒ Object
-
#initialize(node) ⇒ HashedDoc
constructor
A new instance of HashedDoc.
- #to_doc ⇒ Object
Constructor Details
#initialize(node) ⇒ HashedDoc
Returns a new instance of HashedDoc.
21 22 23 24 25 26 |
# File 'lib/rexle-diff.rb', line 21 def initialize(node) @node = node @node.hashed = hash(node) + hashit(node).inject(:+) end |
Instance Method Details
#hash(element) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rexle-diff.rb', line 32 def hash(element) attributes = element.attributes.clone %i(created last_modified).each {|x| attributes.delete x} [element.name, attributes, element.text.to_s.strip].hash end |
#hashit(node) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rexle-diff.rb', line 40 def hashit(node) a = node.elements.map do |element| row = hash element if element.has_elements? r = hashit(element) sum = row + r.inject(:+) element.hashed = sum sum else element.hashed = row row end end end |
#to_doc ⇒ Object
28 29 30 |
# File 'lib/rexle-diff.rb', line 28 def to_doc() @node end |