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
inherited
Methods inherited from Formatter
#apply_advice, #default_advice, #finish, #notify, #receive_advice, #saw_begin_list, #saw_end_list, #saw_item, #start
Constructor Details
#initialize(out = nil, err = nil, indent = " ", newline = "\n") ⇒ XMLFormatter
Returns a new instance of XMLFormatter.
8
9
10
11
12
13
|
# File 'lib/command-set/formatter/xml.rb', line 8
def initialize(out = nil, err = nil, indent=" ", newline="\n")
super(out, err)
@indent = indent
@newline = newline
@indent_level=0
end
|
Instance Method Details
#closed_begin_list(name) ⇒ Object
19
20
21
22
|
# File 'lib/command-set/formatter/xml.rb', line 19
def closed_begin_list(name)
line "<#{name}#{xmlize_options(name)}>"
@indent_level += 1
end
|
#closed_end_list(name) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/command-set/formatter/xml.rb', line 28
def closed_end_list(name)
@indent_level -= 1
if @indent_level < 0
@indent_level = 0
return
end
line "</#{name}>"
end
|
#closed_item(value) ⇒ Object
24
25
26
|
# File 'lib/command-set/formatter/xml.rb', line 24
def closed_item(value)
line "<item value=\"#{value}\"#{xmlize_options(value)} />"
end
|
#line(string) ⇒ Object
15
16
17
|
# File 'lib/command-set/formatter/xml.rb', line 15
def line(string)
print "#{@indent * @indent_level}#{string}#@newline"
end
|