class XMLFormat::Emitter

Public Class Methods

new(out) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 117
def initialize(out)
  @out = out
  @indent = 0
end

Public Instance Methods

emit_line(str) click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 135
def emit_line(str)
  @out.puts((' ' * @indent) + str)
end
emit_tag(obj, tag, *fields) { || ... } click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 122
def emit_tag(obj, tag, *fields, &block)
  expanded = fields.map {|fld| "#{fld}=\"#{obj.send(fld)}\""}
  if block.nil?
    emit_line "<#{tag} #{expanded.join(' ')}/>"
  else
    emit_line "<#{tag} #{expanded.join(' ')}>"
    push
    yield unless block.nil?
    pop
    emit_line "</#{tag}>"
  end
end
pop() click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 143
def pop
  @indent -= 2
end
push() click to toggle source
# File lib/thinp_xml/thinp/xml_format.rb, line 139
def push
  @indent += 2
end