Class: Habdsl::JsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/habdsl/json_parser.rb

Overview

Parser for JSON input

Class Method Summary collapse

Class Method Details

.parse(input_code:, json_code:) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
# File 'lib/habdsl/json_parser.rb', line 9

def self.parse(input_code:, json_code:)
  table = JSON.parse(json_code, symbolize_names: true)

  raise ArgumentError, "Parsed JSON must be an Array of hashes" unless table.is_a?(Array)

  raise ArgumentError, "JSON data array is empty" if table.empty?

  BaseParser.evaluate_dsl(input_code: input_code, table: table)
end