Class: Dachsfisch::JSON2XMLConverter
- Inherits:
-
ConverterBase
- Object
- ConverterBase
- Dachsfisch::JSON2XMLConverter
- Defined in:
- lib/dachsfisch/json2_xml_converter.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(json:) ⇒ JSON2XMLConverter
constructor
A new instance of JSON2XMLConverter.
Methods inherited from ConverterBase
Constructor Details
#initialize(json:) ⇒ JSON2XMLConverter
Returns a new instance of JSON2XMLConverter.
5 6 7 8 9 10 |
# File 'lib/dachsfisch/json2_xml_converter.rb', line 5 def initialize(json:) super() @json_hash = JSON.parse json rescue TypeError, JSON::ParserError => e raise InvalidJSONInputError.new(e.) end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/dachsfisch/json2_xml_converter.rb', line 12 def execute fragment = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new) Nokogiri::XML::Builder.with fragment do |xml| add_element xml, @json_hash end fragment.elements.deconstruct.map(&:to_xml).join("\n") end |