Sha256: 27d9d3ab0c16b1ee0fda75dfc7e6361cd96a521a135ec7e0a5382698081f0873
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true module EDL # Is used to parse an EDL # Parsing errors are collected in +errors+ class Parser attr_reader :fps attr_accessor :errors # Initialize an EDL parser. Pass the FPS to it, as the usual EDL does not contain any kind of reference # to it's framerate def initialize(with_fps = DEFAULT_FPS) @fps = with_fps end def get_matchers #:nodoc: [EventMatcher.new(@fps), EffectMatcher.new, NameMatcher.new, TimewarpMatcher.new(@fps), CommentMatcher.new] end # Parse a passed File or IO object line by line, or the whole string 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 # Init a Timecode object from the passed elements with the passed framerate def self.timecode_from_line_elements(elements, fps) #:nodoc: args = (0..3).map { |_| elements.shift.to_i } + [fps.to_f] Timecode.at(*args) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
edl-0.1.7 | lib/edl/parser.rb |
edl-0.1.6 | lib/edl/parser.rb |