edl 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/lib/edl.rb +3 -2
- data/lib/edl/linebreak_magician.rb +24 -0
- data/lib/edl/parser.rb +4 -7
- data/test/test_edl.rb +1 -1
- metadata +5 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/lib/edl.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "timecode"
|
3
|
-
require
|
3
|
+
require "stringio"
|
4
4
|
|
5
5
|
require File.dirname(__FILE__) + '/edl/event'
|
6
6
|
require File.dirname(__FILE__) + '/edl/transition'
|
7
7
|
require File.dirname(__FILE__) + '/edl/timewarp'
|
8
8
|
require File.dirname(__FILE__) + '/edl/parser'
|
9
|
+
require File.dirname(__FILE__) + '/edl/linebreak_magician'
|
9
10
|
|
10
11
|
# A simplistic EDL parser
|
11
12
|
module EDL
|
12
|
-
VERSION = "0.1.
|
13
|
+
VERSION = "0.1.2"
|
13
14
|
DEFAULT_FPS = 25.0
|
14
15
|
|
15
16
|
# Represents an EDL, is returned from the parser. Traditional operation is functional style, i.e.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
# EDLs sometimes come with \r line breaks, and this is something that fails
|
4
|
+
# with Ruby standard line separator detection. We need something to help us
|
5
|
+
# with that
|
6
|
+
class EDL::LinebreakMagician < DelegateClass(IO)
|
7
|
+
|
8
|
+
def initialize(with_file)
|
9
|
+
sample = with_file.read(2048)
|
10
|
+
@linebreak = ["\r\n", "\r", "\n"].find{|separator| sample.include?(separator) }
|
11
|
+
with_file.rewind
|
12
|
+
__setobj__(with_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(sep_string = $/, &blk)
|
16
|
+
super(@linebreak || sep_string, &blk)
|
17
|
+
end
|
18
|
+
alias_method :each_line, :each
|
19
|
+
|
20
|
+
def gets(sep_string = $/)
|
21
|
+
super(@linebreak || sep_string)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/edl/parser.rb
CHANGED
@@ -17,24 +17,21 @@ module EDL
|
|
17
17
|
|
18
18
|
# Parse a passed File or IO object line by line, or the whole string
|
19
19
|
def parse(input_string_or_io)
|
20
|
-
return parse(input_string_or_io
|
20
|
+
return parse(StringIO.new(input_string_or_io)) unless input_string_or_io.respond_to?(:read)
|
21
21
|
|
22
|
-
|
23
|
-
input_string_or_io.gsub!(/(\r\n|\r)/, "\n")
|
24
|
-
input_in_io = StringIO.new(input_string_or_io)
|
22
|
+
magic = ::EDL::LinebreakMagician.new(input_string_or_io)
|
25
23
|
|
26
24
|
# Normalize line breaks
|
27
25
|
stack, matchers = List.new, get_matchers
|
28
26
|
|
29
|
-
|
27
|
+
while current_line = magic.gets
|
30
28
|
|
31
|
-
current_line = input_in_io.gets.strip
|
32
29
|
m = matchers.find{|m| m.matches?(current_line) }
|
33
30
|
|
34
31
|
next unless m
|
35
32
|
begin
|
36
33
|
m.apply(stack, current_line)
|
37
|
-
stack[-1].line_number =
|
34
|
+
stack[-1].line_number = magic.lineno if m.is_a?(EventMatcher)
|
38
35
|
rescue Matcher::ApplyError => e
|
39
36
|
STDERR.puts "Cannot parse #{current_line} - #{e}"
|
40
37
|
end
|
data/test/test_edl.rb
CHANGED
@@ -605,7 +605,7 @@ context "A complex EDL passed via Parser should" do
|
|
605
605
|
assert_nothing_raised { EDL::Parser.new.parse(File.open(FORTY_FIVER)) }
|
606
606
|
end
|
607
607
|
|
608
|
-
specify "parse the
|
608
|
+
specify "parse the EDL with \\r line breaks properly" do
|
609
609
|
evts = EDL::Parser.new.parse(File.read(PLATES))
|
610
610
|
assert_equal 3, evts.length
|
611
611
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Julik Tarkhanov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-23 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/edl/event.rb
|
123
123
|
- lib/edl/grabber.rb
|
124
124
|
- lib/edl/parser.rb
|
125
|
+
- lib/edl/linebreak_magician.rb
|
125
126
|
- lib/edl/timewarp.rb
|
126
127
|
- lib/edl/transition.rb
|
127
128
|
- test/.DS_Store
|