Class: Command::Results::XMLFormatter
Overview
A trivial and obvious Formatter: produces well-formed XML fragments based on events. It even indents. Might be handy for more complicated output processing, since you could feed the document to a XSLT processor.
Instance Attribute Summary
Attributes inherited from Formatter
#advice
Instance Method Summary
collapse
Methods inherited from Formatter
#apply_advice, #default_advice, #finish, inherited, #notify, #receive_advice, #saw_begin_list, #saw_end_list, #saw_item, #start
Constructor Details
#initialize(io, indent = " ", newline = "\n") ⇒ XMLFormatter
Returns a new instance of XMLFormatter.
718
719
720
721
722
723
|
# File 'lib/command-set/results.rb', line 718
def initialize(io, indent=" ", newline="\n")
super(io)
@indent = indent
@newline = newline
@indent_level=0
end
|
Instance Method Details
#closed_begin_list(name) ⇒ Object
729
730
731
732
|
# File 'lib/command-set/results.rb', line 729
def closed_begin_list(name)
line "<#{name}>"
@indent_level += 1
end
|
#closed_end_list(name) ⇒ Object
738
739
740
741
742
743
744
745
|
# File 'lib/command-set/results.rb', line 738
def closed_end_list(name)
@indent_level -= 1
if @indent_level < 0
@indent_level = 0
return
end
line "</#{name}>"
end
|
#closed_item(value) ⇒ Object
734
735
736
|
# File 'lib/command-set/results.rb', line 734
def closed_item(value)
line "<item value=\"#{value}\" />"
end
|
#line(string) ⇒ Object
725
726
727
|
# File 'lib/command-set/results.rb', line 725
def line(string)
print "#{@indent * @indent_level}#{string}#@newline"
end
|