Class: ThinpXML::Base::Emitter

Inherits:
Object
  • Object
show all
Defined in:
lib/thinp_xml/emitter.rb

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Emitter

Returns a new instance of Emitter.



6
7
8
9
# File 'lib/thinp_xml/emitter.rb', line 6

def initialize(out)
  @out = out
  @indent = 0
end

Instance Method Details

#emit_line(str) ⇒ Object



24
25
26
# File 'lib/thinp_xml/emitter.rb', line 24

def emit_line(str)
  @out.puts((' ' * @indent) + str)
end

#emit_tag(obj, tag, *fields, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# 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