class ThinpXML::Base::Emitter
Public Class Methods
new(out)
click to toggle source
# File lib/thinp_xml/emitter.rb, line 6 def initialize(out) @out = out @indent = 0 end
Public Instance Methods
emit_line(str)
click to toggle source
# File lib/thinp_xml/emitter.rb, line 24 def emit_line(str) @out.puts((' ' * @indent) + str) end
emit_tag(obj, tag, *fields) { || ... }
click to toggle source
# File lib/thinp_xml/emitter.rb, line 11 def emit_tag(obj, tag, *fields, &block) expanded = fields.map {|fld| "#{fld}=\"#{obj.send(fld)}\""} if block.nil? emit_line "<#{tag}#{join_fields(expanded)}/>" else emit_line "<#{tag}#{join_fields(expanded)}>" push yield unless block.nil? pop emit_line "</#{tag}>" end end
Private Instance Methods
join_fields(fields)
click to toggle source
# File lib/thinp_xml/emitter.rb, line 30 def join_fields(fields) fields.size == 0 ? "" : " #{fields.join(' ')}" end
pop()
click to toggle source
# File lib/thinp_xml/emitter.rb, line 38 def pop @indent -= 2 end
push()
click to toggle source
# File lib/thinp_xml/emitter.rb, line 34 def push @indent += 2 end