Class: EDL::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/edl/parser.rb

Overview

Is used to parse an EDL Parsing errors are collected in errors

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(with_fps = DEFAULT_FPS) ⇒ Parser

Initialize an EDL parser. Pass the FPS to it, as the usual EDL does not contain any kind of reference to it's framerate


12
13
14
# File 'lib/edl/parser.rb', line 12

def initialize(with_fps = DEFAULT_FPS)
  @fps = with_fps
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors


8
9
10
# File 'lib/edl/parser.rb', line 8

def errors
  @errors
end

#fpsObject (readonly)

Returns the value of attribute fps


7
8
9
# File 'lib/edl/parser.rb', line 7

def fps
  @fps
end

Class Method Details

.timecode_from_line_elements(elements, fps) ⇒ Object

Init a Timecode object from the passed elements with the passed framerate


48
49
50
51
# File 'lib/edl/parser.rb', line 48

def self.timecode_from_line_elements(elements, fps) #:nodoc:
  args = (0..3).map { |_| elements.shift.to_i } + [fps.to_f]
  Timecode.at(*args)
end

Instance Method Details

#get_matchersObject

:nodoc:


16
17
18
# File 'lib/edl/parser.rb', line 16

def get_matchers #:nodoc:
  [EventMatcher.new(@fps), EffectMatcher.new, NameMatcher.new, TimewarpMatcher.new(@fps), CommentMatcher.new]
end

#parse(input_string_or_io) ⇒ Object

Parse a passed File or IO object line by line, or the whole string


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/edl/parser.rb', line 21

def parse(input_string_or_io)
  return parse(StringIO.new(input_string_or_io)) unless input_string_or_io.respond_to?(:read)
  self.errors = []

  magic = EDL::LinebreakMagician.new(input_string_or_io)

  # Normalize line breaks
  stack = List.new
  matchers = get_matchers

  while current_line = magic.gets
    m = matchers.find { |m| m.matches?(current_line) }

    next unless m
    begin
      m.apply(stack, current_line)
      stack[-1].line_number = magic.lineno if m.is_a?(EventMatcher)
    rescue Matcher::ApplyError => e
      error = "Cannot parse #{current_line} - #{e}"
      errors << error
      STDERR.puts error
    end
  end
  stack
end