lib/edl.rb in edl-0.0.5 vs lib/edl.rb in edl-0.0.6

- old
+ new

@@ -6,11 +6,11 @@ require File.dirname(__FILE__) + '/edl/transition' require File.dirname(__FILE__) + '/edl/timewarp' # A simplistic EDL parser module EDL - VERSION = "0.0.5" + VERSION = "0.0.6" DEFAULT_FPS = 25 # Represents an EDL, is returned from the parser. Traditional operation is functional style, i.e. # edl.renumbered.without_transitions.without_generators class List < Array @@ -157,10 +157,25 @@ def apply(stack, line) stack[-1].comments << line.scan(@regexp).flatten.pop.strip end end + + # Fallback matcher for things like FINAL CUT PRO REEL + class FallbackMatcher < Matcher + def initialize + super(/^(\w)(.+)/) + end + + def apply(stack, line) + begin + stack[-1].comments << line.scan(@regexp).flatten.join.strip + rescue NoMethodError + raise ApplyError.new("Line can only be a comment but no event was on the stack", line) + end + end + end # Clip name matcher class NameMatcher < Matcher def initialize super(/\* FROM CLIP NAME:(\s+)(.+)/) @@ -320,17 +335,16 @@ return parse(StringIO.new(io.to_s)) unless io.respond_to?(:eof?) stack, matchers = List.new, get_matchers until io.eof? current_line = io.gets.strip - matchers.each do | matcher | - next unless matcher.matches?(current_line) - - begin - matcher.apply(stack, current_line) - rescue Matcher::ApplyError => e - STDERR.puts "Cannot parse #{current_line} - #{e}" - end + m = matchers.find{|m| m.matches?(current_line) } + next unless m + + begin + m.apply(stack, current_line) + rescue Matcher::ApplyError => e + STDERR.puts "Cannot parse #{current_line} - #{e}" end end stack end \ No newline at end of file