lib/rcap/cap_1_2/alert.rb in rcap-1.0.0.rc.5 vs lib/rcap/cap_1_2/alert.rb in rcap-1.0.0
- old
+ new
@@ -166,12 +166,18 @@
xml_document.add( self.to_xml_element )
xml_document
end
# Returns a string containing the XML representation of the alert.
- def to_xml
- self.to_xml_document.to_s
+ def to_xml( pretty_print = false )
+ if pretty_print
+ xml_document = ""
+ XML_PRETTY_PRINTER.write( self.to_xml_document, xml_document )
+ xml_document
+ else
+ self.to_xml_document.to_s
+ end
end
# Returns a string representation of the alert suitable for usage as a reference in a CAP message of the form
# sender,identifier,sent
def to_reference
@@ -346,11 +352,15 @@
:incidents => alert_hash[ INCIDENTS_KEY ],
:infos => Array( alert_hash[ INFOS_KEY ]).map{ |info_hash| Info.from_h( info_hash )})
end
# Returns a JSON string representation of an Alert object
- def to_json
- self.to_h.to_json
+ def to_json( pretty_print = false )
+ if pretty_print
+ JSON.pretty_generate( self.to_h )
+ else
+ self.to_h.to_json
+ end
end
# Initiialises an Alert object from a JSON string produced by Alert#to_json
def self.from_json( json_string )
self.from_h( JSON.parse( json_string ))