Module: Ace::Demo::Atoms::CastFileParser

Defined in:
lib/ace/demo/atoms/cast_file_parser.rb

Class Method Summary collapse

Class Method Details

.parse(path) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ace/demo/atoms/cast_file_parser.rb', line 11

def parse(path)
  raise CastParseError, "Cast file not found: #{path}" unless File.exist?(path)

  header = nil
  events = []

  File.foreach(path).with_index(1) do |line, line_number|
    stripped = line.strip
    next if stripped.empty?

    json = JSON.parse(stripped)
    if header.nil?
      header = parse_header(json, path: path)
    else
      events << parse_event(json, path: path, line_number: line_number)
    end
  rescue JSON::ParserError => e
    raise CastParseError, "Invalid JSON in #{path}:#{line_number}: #{e.message}"
  end

  raise CastParseError, "Missing cast header in #{path}" if header.nil?

  Models::CastRecording.new(header: header, events: events)
end