tc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tc/duration.rb +7 -5
- data/lib/tc/version.rb +1 -1
- data/spec/lib/tc_duration_spec.rb +26 -0
- metadata +4 -4
data/lib/tc/duration.rb
CHANGED
@@ -26,7 +26,7 @@ class Tc::Duration < Parslet::Parser
|
|
26
26
|
|
27
27
|
# unit strings
|
28
28
|
rule(:s_seconds) { ((space? >> stri('s') >> (stri('ec') >> stri('s').maybe).maybe >> (str('.') | stri('ond')).maybe >> stri('s').maybe) | str('"'))}
|
29
|
-
rule(:s_minutes) { ((space? >> stri('m') >> stri('in').maybe >> (str('.') | (stri('ute') >> stri('s')).maybe).maybe) | str("'"))}
|
29
|
+
rule(:s_minutes) { ((space? >> stri('m') >> stri('in').maybe >> (str('.') | str('s') | (stri('ute') >> stri('s')).maybe).maybe) | str("'"))}
|
30
30
|
rule(:s_hours) { (space? >> stri('h') >> ((stri('r') >> stri('s').maybe >> str('.').maybe) | (stri('our').maybe >> stri('s').maybe )).maybe) }
|
31
31
|
|
32
32
|
# unit values
|
@@ -46,7 +46,9 @@ class Tc::Duration < Parslet::Parser
|
|
46
46
|
rule(:min) { arbitrary_length_integer }
|
47
47
|
|
48
48
|
# hours
|
49
|
-
rule(:
|
49
|
+
rule(:zero_to_three) { match('[0-3]') >> integer.absnt?}
|
50
|
+
rule(:zero_zero_to_zero_three) { str('0') >> match('[0-3]') >> integer.absnt?}
|
51
|
+
rule(:small_h) { (zero_to_three | zero_zero_to_zero_three) }
|
50
52
|
|
51
53
|
# unit matchers
|
52
54
|
rule(:frames) { (ndf_separator | df_separator) >> (ff | frame).as(:frames) }
|
@@ -91,10 +93,10 @@ class Tc::Duration < Parslet::Parser
|
|
91
93
|
rule(:timecode) { approximate | exact }
|
92
94
|
|
93
95
|
# header tokens
|
94
|
-
rule(:trt) { str('TRT').as(:trt) >> space? }
|
95
|
-
rule(:colon_prefix) { str(':') }
|
96
|
+
rule(:trt) { str('TRT').as(:trt) >> space? >> timecode }
|
97
|
+
rule(:colon_prefix) { str(':') >> timecode }
|
96
98
|
|
97
|
-
rule(:duration) {
|
99
|
+
rule(:duration) { trt | colon_prefix | timecode }
|
98
100
|
|
99
101
|
root :duration
|
100
102
|
end
|
data/lib/tc/version.rb
CHANGED
@@ -66,6 +66,10 @@ describe Tc::Duration do
|
|
66
66
|
it "should consume 'minutes'" do
|
67
67
|
parser.s_minutes.should parse(' minutes')
|
68
68
|
end
|
69
|
+
|
70
|
+
it "should consume 'mins'" do
|
71
|
+
parser.s_minutes.should parse('mins')
|
72
|
+
end
|
69
73
|
end
|
70
74
|
|
71
75
|
context "m" do
|
@@ -98,6 +102,10 @@ describe Tc::Duration do
|
|
98
102
|
parser.small_h.should parse('01')
|
99
103
|
end
|
100
104
|
|
105
|
+
it "should consume '0'" do
|
106
|
+
parser.small_h.should parse('0')
|
107
|
+
end
|
108
|
+
|
101
109
|
it "should consume '2'" do
|
102
110
|
parser.small_h.should parse('2')
|
103
111
|
end
|
@@ -111,6 +119,10 @@ describe Tc::Duration do
|
|
111
119
|
it "should consume '01:09:26 s'" do
|
112
120
|
parser.small_h_m_s.should parse('01:09:26 s')
|
113
121
|
end
|
122
|
+
|
123
|
+
it "should consume '0:28:46'" do
|
124
|
+
parser.small_h_m_s.should parse('0:28:46')
|
125
|
+
end
|
114
126
|
|
115
127
|
it "should not consume '275:00:00'" do
|
116
128
|
parser.small_h_m_s.should_not parse('275:00:00')
|
@@ -119,6 +131,7 @@ describe Tc::Duration do
|
|
119
131
|
it "should not consume '4:52:12'" do
|
120
132
|
parser.small_h_m_s.should_not parse('4:52:12')
|
121
133
|
end
|
134
|
+
|
122
135
|
end
|
123
136
|
|
124
137
|
context 's_hours' do
|
@@ -318,6 +331,15 @@ describe Tc::Duration do
|
|
318
331
|
parsed[:seconds].should == '02.042'
|
319
332
|
end
|
320
333
|
|
334
|
+
it "should parse '0:51:36'" do
|
335
|
+
parser.exact.should parse('0:51:36')
|
336
|
+
parsed = parser.exact.parse('0:51:36')
|
337
|
+
|
338
|
+
parsed[:hours].should == '0'
|
339
|
+
parsed[:minutes].should == '51'
|
340
|
+
parsed[:seconds].should == '36'
|
341
|
+
end
|
342
|
+
|
321
343
|
it "should parse '0.26875'" do
|
322
344
|
parser.exact.should parse('0.26875')
|
323
345
|
parsed = parser.exact.parse('0.26875')
|
@@ -488,5 +510,9 @@ describe Tc::Duration do
|
|
488
510
|
it "should consume ':00:26:30'" do
|
489
511
|
parser.duration.should parse(':00:26:30')
|
490
512
|
end
|
513
|
+
|
514
|
+
it "should consume ':00:03:30'" do
|
515
|
+
parser.duration.should parse(':00:03:30')
|
516
|
+
end
|
491
517
|
end
|
492
518
|
end
|
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.2
|
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-11 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: &2165631040 !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: *2165631040
|
26
26
|
description: Timecode parsing
|
27
27
|
email:
|
28
28
|
- chris_beer@wgbh.org
|