Class: XmlPatch::DiffDocument

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xml_patch/diff_document.rb

Instance Method Summary collapse

Constructor Details

#initializeDiffDocument

Returns a new instance of DiffDocument.



5
6
7
# File 'lib/xml_patch/diff_document.rb', line 5

def initialize
  @operations = []
end

Instance Method Details

#<<(operation) ⇒ Object



9
10
11
12
# File 'lib/xml_patch/diff_document.rb', line 9

def <<(operation)
  operations << operation
  self
end

#==(other) ⇒ Object



23
24
25
26
27
# File 'lib/xml_patch/diff_document.rb', line 23

def ==(other)
  other.respond_to?(:apply_to) &&
    other.respond_to?(:zip) &&
    other.zip(self).all? { |a, b| a == b }
end

#apply_to(doc) ⇒ Object



18
19
20
21
# File 'lib/xml_patch/diff_document.rb', line 18

def apply_to(doc)
  operations.each { |op| op.apply_to(doc) }
  doc
end

#each(&blk) ⇒ Object



14
15
16
# File 'lib/xml_patch/diff_document.rb', line 14

def each(&blk)
  operations.each(&blk)
end

#to_xmlObject



29
30
31
32
33
34
35
# File 'lib/xml_patch/diff_document.rb', line 29

def to_xml
  if operations.empty?
    '<diff />'
  else
    '<diff>' + operations.map(&:to_xml).join("\n") + '</diff>'
  end
end