Module: Dcc::Convert::Json
- Defined in:
- lib/dcc/convert/json.rb
Overview
Dcc::Convert::Json serializes a parsed DCC to JSON by converting
the to_xml output to a JSON-compatible hash.
Class Method Summary collapse
Class Method Details
.call(dcc, pretty: true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dcc/convert/json.rb', line 11 def call(dcc, pretty: true) hash = xml_to_hash(dcc.to_xml) payload = pretty ? ::JSON.pretty_generate(hash) : ::JSON.generate(hash) ::Dcc::Convert::Result.new( format: :json, payload: payload, source_class: dcc.class.name, schema_version: dcc.schema_version.to_s, ) end |
.xml_to_hash(xml_string) ⇒ Object
22 23 24 25 |
# File 'lib/dcc/convert/json.rb', line 22 def xml_to_hash(xml_string) doc = ::Lutaml::Model::Config.xml_adapter.parse(xml_string) element_to_hash(doc.root) end |