Class: XMLPurifier
- Inherits:
-
Object
- Object
- XMLPurifier
- Defined in:
- lib/xml-purifier.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ XMLPurifier
constructor
A new instance of XMLPurifier.
- #to_xml ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ XMLPurifier
Returns a new instance of XMLPurifier.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/xml-purifier.rb', line 11 def initialize(={}) # options for to: default, native, cdata, escaped opt = {xml: '', from: 'json', to: 'native'}.merge() @doc = Document.new(opt[:xml]) @doc.root.each_recursive do |elem| if elem.text and elem.text.to_s[/^[\{\[][^\}\]]+[\}\]]$/] then obj = JSON.parse(elem.text) method('to_' + opt[:to].to_s.to_sym).call(elem, scan_obj_to_xml(obj)) end end end |
Instance Method Details
#to_xml ⇒ Object
29 |
# File 'lib/xml-purifier.rb', line 29 def to_xml() @doc.to_s end |