Class: EDL::Parser

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

Overview

Is used to parse an EDL

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



10
11
12
# File 'lib/edl/parser.rb', line 10

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

Instance Attribute Details

#fpsObject (readonly)

Returns the value of attribute fps.



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

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



43
44
45
46
# File 'lib/edl/parser.rb', line 43

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:



14
15
16
# File 'lib/edl/parser.rb', line 14

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



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

def parse(input_string_or_io)
  return parse(StringIO.new(input_string_or_io)) unless input_string_or_io.respond_to?(:read)
  
  magic = ::EDL::LinebreakMagician.new(input_string_or_io)
  
  # Normalize line breaks
  stack, matchers = List.new, 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
      STDERR.puts "Cannot parse #{current_line} - #{e}"
    end
  end
  stack
end