Class: Tabled::JSONParser

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

Class Method Summary collapse

Class Method Details

.parse(file_path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/parsers/json_parser.rb', line 6

def self.parse(file_path)
  file = File.read(file_path)
  json_entries = ::JSON.parse(file)

  unless json_entries.is_a?(Array) && json_entries.first.is_a?(Hash)
    raise ArgumentError, 'Invalid JSON format. Expected an array of objects.'
  end

  [json_entries.first.keys, json_entries.map(&:values)]
end