tc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tc/duration.rb +6 -1
- data/lib/tc/version.rb +1 -1
- data/spec/lib/tc_duration_spec.rb +18 -0
- metadata +4 -4
data/lib/tc/duration.rb
CHANGED
@@ -49,6 +49,7 @@ class Tc::Duration < Parslet::Parser
|
|
49
49
|
rule(:zero_to_three) { match('[0-3]') >> integer.absnt?}
|
50
50
|
rule(:zero_zero_to_zero_three) { str('0') >> match('[0-3]') >> integer.absnt?}
|
51
51
|
rule(:small_h) { (zero_to_three | zero_zero_to_zero_three) }
|
52
|
+
rule(:small_m) { ((match('[0-3]') >> integer >> integer) | (integer >> integer) ).as(:minutes) >> integer.absnt?}
|
52
53
|
|
53
54
|
# unit matchers
|
54
55
|
rule(:frames) { (ndf_separator | df_separator) >> (ff | frame).as(:frames) }
|
@@ -61,6 +62,10 @@ class Tc::Duration < Parslet::Parser
|
|
61
62
|
rule(:h) { hours >> s_hours.maybe }
|
62
63
|
rule(:m) { minutes >> s_minutes.maybe }
|
63
64
|
|
65
|
+
rule(:m_mins) { minutes >> s_minutes }
|
66
|
+
rule(:s_secs) { seconds >> s_seconds }
|
67
|
+
|
68
|
+
|
64
69
|
# timecode matchers
|
65
70
|
rule(:smpte) { hh.as(:hours) >> separator >> mm.as(:minutes) >> separator >> ss.as(:seconds) >> frames }
|
66
71
|
rule(:h_m) { hours >> separator >> minutes >> s_minutes.maybe }
|
@@ -74,7 +79,7 @@ class Tc::Duration < Parslet::Parser
|
|
74
79
|
rule(:min_sec) { minutes >> s_minutes >> space? >> (seconds >> s_seconds.maybe).maybe }
|
75
80
|
|
76
81
|
rule(:unambiguous) { smpte | small_h_m_s | hr_min | hr_min_sec | min_sec }
|
77
|
-
rule(:ambiguous) { m_s_f | h_m_s | m_s | h_m |
|
82
|
+
rule(:ambiguous) { m_s_f | h_m_s | m_s | h_m | m_mins | s_secs | small_m | s | m }
|
78
83
|
rule(:exact) { unambiguous | ambiguous }
|
79
84
|
|
80
85
|
# approximate indicators
|
data/lib/tc/version.rb
CHANGED
@@ -115,6 +115,16 @@ describe Tc::Duration do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
+
context "small_m" do
|
119
|
+
it "should consume '300'" do
|
120
|
+
parser.small_m.should parse('300')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not consume '1234'" do
|
124
|
+
parser.small_m.should_not parse('1234')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
118
128
|
context "small_h_m_s" do
|
119
129
|
it "should consume '01:09:26 s'" do
|
120
130
|
parser.small_h_m_s.should parse('01:09:26 s')
|
@@ -426,9 +436,17 @@ describe Tc::Duration do
|
|
426
436
|
parsed[:seconds].should == '5100.0'
|
427
437
|
end
|
428
438
|
|
439
|
+
it "should parse '5678'" do
|
440
|
+
parser.exact.should parse('5678')
|
441
|
+
parsed = parser.exact.parse('5678')
|
442
|
+
|
443
|
+
parsed[:seconds].should == '5678'
|
444
|
+
end
|
445
|
+
|
429
446
|
it "should parse '120'" do
|
430
447
|
parser.exact.should parse('120')
|
431
448
|
parsed = parser.exact.parse('120')
|
449
|
+
|
432
450
|
parsed[:minutes].should == '120'
|
433
451
|
end
|
434
452
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-24 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parslet
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157124960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157124960
|
26
26
|
description: Timecode parsing
|
27
27
|
email:
|
28
28
|
- chris_beer@wgbh.org
|