Class: JsonToToon::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/json_to_toon/converter.rb

Class Method Summary collapse

Class Method Details

.convert(json_string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json_to_toon/converter.rb', line 9

def self.convert(json_string)
  raise ArgumentError, 'Input must be a String.' unless json_string.is_a?(String)

  data_hash = JSON.parse(json_string, symbolize_names: true)

  root_node = NodeBuilder.build(data_hash)
  root_node.to_s
rescue JSON::ParserError => e
  raise ConversionError, "Invalid JSON structure provided: #{e.message}"
rescue StandardError => e
  raise Error, "An unexpected error occurred during conversion: #{e.message}"
end