Class: PostRemoteLog::SimpleXMLBuilder

Inherits:
StringIO
  • Object
show all
Defined in:
lib/post_remote_log/simple_xml.rb

Overview

Very simple XML builder to minimize dependencies:

Constant Summary collapse

X =
{"<" => "&lt;", ">" => "&gt;"}

Instance Method Summary collapse

Constructor Details

#initializeSimpleXMLBuilder

Returns a new instance of SimpleXMLBuilder.



24
25
26
27
28
# File 'lib/post_remote_log/simple_xml.rb', line 24

def initialize
  super
 
  @level = 0
end

Instance Method Details

#instruct!Object



30
31
32
# File 'lib/post_remote_log/simple_xml.rb', line 30

def instruct!
  self.puts '<?xml version="1.0" encoding="UTF-8"?>'
end

#tag(name, &block) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/post_remote_log/simple_xml.rb', line 39

def tag(name, &block)
  self.puts tab + "<#{name}>"
  @level += 1
  yield
  @level -= 1
  self.puts tab + "</#{name}>"
end

#value(name, value) ⇒ Object



34
35
36
37
# File 'lib/post_remote_log/simple_xml.rb', line 34

def value(name, value)
  value.gsub!(/<|>/) { |s| X[s] }
  self.puts tab +  "<#{name}>" + value.to_s + "</#{name}>"
end