Class: PostRemoteLog::SimpleXMLBuilder
- Inherits:
-
StringIO
- Object
- StringIO
- PostRemoteLog::SimpleXMLBuilder
- Defined in:
- lib/post_remote_log/simple_xml.rb
Overview
Very simple XML builder to minimize dependencies:
Constant Summary collapse
- X =
{"<" => "<", ">" => ">"}
Instance Method Summary collapse
-
#initialize ⇒ SimpleXMLBuilder
constructor
A new instance of SimpleXMLBuilder.
- #instruct! ⇒ Object
- #tag(name, &block) ⇒ Object
- #value(name, value) ⇒ Object
Constructor Details
#initialize ⇒ SimpleXMLBuilder
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 |