Class: XMLFormat::Emitter
- Inherits:
-
Object
- Object
- XMLFormat::Emitter
- Defined in:
- lib/thinp_xml/thinp/xml_format.rb
Instance Method Summary collapse
- #emit_line(str) ⇒ Object
- #emit_tag(obj, tag, *fields, &block) ⇒ Object
-
#initialize(out) ⇒ Emitter
constructor
A new instance of Emitter.
- #pop ⇒ Object
- #push ⇒ Object
Constructor Details
#initialize(out) ⇒ Emitter
Returns a new instance of Emitter.
115 116 117 118 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 115 def initialize(out) @out = out @indent = 0 end |
Instance Method Details
#emit_line(str) ⇒ Object
133 134 135 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 133 def emit_line(str) @out.puts((' ' * @indent) + str) end |
#emit_tag(obj, tag, *fields, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 120 def emit_tag(obj, tag, *fields, &block) = fields.map {|fld| "#{fld}=\"#{obj.send(fld)}\""} if block.nil? emit_line "<#{tag} #{.join(' ')}/>" else emit_line "<#{tag} #{.join(' ')}>" push yield unless block.nil? pop emit_line "</#{tag}>" end end |
#pop ⇒ Object
141 142 143 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 141 def pop @indent -= 2 end |
#push ⇒ Object
137 138 139 |
# File 'lib/thinp_xml/thinp/xml_format.rb', line 137 def push @indent += 2 end |