tc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/LICENSE +7 -0
- data/README.md +23 -0
- data/Rakefile +7 -0
- data/lib/tc/duration.rb +100 -0
- data/lib/tc/version.rb +3 -0
- data/lib/tc.rb +5 -0
- data/spec/lib/tc_duration_spec.rb +492 -0
- data/spec/spec_helper.rb +7 -0
- data/tc.gemspec +22 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011 Chris Beer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Tc
|
2
|
+
|
3
|
+
Timecode parser (based on Parslet) for parsing arbitrary timecode formats into a standardized format
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
parser = Tc::Duration.new
|
9
|
+
|
10
|
+
parser.parse('00:12:43;23')
|
11
|
+
# => { :hours => '00', :minutes => '12', :seconds => '43', :frames => '23', :ndf => ';'}
|
12
|
+
|
13
|
+
parser.parse('123m')
|
14
|
+
# => { :minutes => '123' }
|
15
|
+
|
16
|
+
parser.parse('approx. 54s')
|
17
|
+
# => { :seconds => '54', :approximate => 'approx.' }
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
See ```spec/lib/tc_duration.rb``` for additional examples.
|
22
|
+
|
23
|
+
Given an ambiguously formatted input (e.g. ```01:34```), Tc will prefer ```hh:mm``` for small values of ```hh``` (<= 2 hours), but ```mm:ss``` in all other cases.
|
data/Rakefile
ADDED
data/lib/tc/duration.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'parslet'
|
2
|
+
|
3
|
+
class Tc::Duration < Parslet::Parser
|
4
|
+
def stri(str)
|
5
|
+
key_chars = str.split(//)
|
6
|
+
key_chars.
|
7
|
+
collect! { |char| match["#{char.upcase}#{char.downcase}"] }.
|
8
|
+
reduce(:>>)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
# base units
|
13
|
+
rule(:integer) { match('[0-9]') }
|
14
|
+
rule(:space) { match('\s').repeat(1) }
|
15
|
+
rule(:space?) { space.maybe }
|
16
|
+
|
17
|
+
rule(:arbitrary_length_integer) { integer.repeat(1) }
|
18
|
+
rule(:one_or_two_digit_integer) { integer.repeat(1,2) }
|
19
|
+
rule(:zero_zero_to_fifty_nine) { (match('[0-5]') >> match('[0-9]') | match('[0-9]')) }
|
20
|
+
rule(:zero_zero_to_twenty_nine) { (match('[0-2]') >> match('[0-9]') | match('[0-9]')) }
|
21
|
+
|
22
|
+
#separators
|
23
|
+
rule(:separator) { match(':') }
|
24
|
+
rule(:ndf_separator) { match(':').as(:ndf) }
|
25
|
+
rule(:df_separator) { match(';').as(:df) }
|
26
|
+
|
27
|
+
# unit strings
|
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("'"))}
|
30
|
+
rule(:s_hours) { (space? >> stri('h') >> ((stri('r') >> stri('s').maybe >> str('.').maybe) | (stri('our').maybe >> stri('s').maybe )).maybe) }
|
31
|
+
|
32
|
+
# unit values
|
33
|
+
|
34
|
+
# idealized
|
35
|
+
rule(:ff) { zero_zero_to_twenty_nine >> integer.absnt? }
|
36
|
+
rule(:ss) { zero_zero_to_fifty_nine }
|
37
|
+
rule(:mm) { zero_zero_to_fifty_nine >> integer.absnt? }
|
38
|
+
rule(:hh) { arbitrary_length_integer }
|
39
|
+
|
40
|
+
# seconds
|
41
|
+
rule(:sec) { arbitrary_length_integer }
|
42
|
+
rule(:fraction) { str('.') >> arbitrary_length_integer }
|
43
|
+
rule(:frame) { zero_zero_to_fifty_nine >> integer.absnt? }
|
44
|
+
|
45
|
+
# minutes
|
46
|
+
rule(:min) { arbitrary_length_integer }
|
47
|
+
|
48
|
+
# hours
|
49
|
+
rule(:small_h) { str('0').maybe >> match('[0-2]') >> integer.absnt? }
|
50
|
+
|
51
|
+
# unit matchers
|
52
|
+
rule(:frames) { (ndf_separator | df_separator) >> (ff | frame).as(:frames) }
|
53
|
+
rule(:seconds_f) { ((sec >> fraction).as(:seconds) | ( sec.as(:seconds) >> frames )) }
|
54
|
+
rule(:seconds) { (seconds_f | sec.as(:seconds) ) }
|
55
|
+
rule(:minutes) { (mm | min).as(:minutes) >> (integer | str('.')).absnt? }
|
56
|
+
rule(:hours) { hh.as(:hours) }
|
57
|
+
|
58
|
+
rule(:s) { seconds >> s_seconds.maybe }
|
59
|
+
rule(:h) { hours >> s_hours.maybe }
|
60
|
+
rule(:m) { minutes >> s_minutes.maybe }
|
61
|
+
|
62
|
+
# timecode matchers
|
63
|
+
rule(:smpte) { hh.as(:hours) >> separator >> mm.as(:minutes) >> separator >> ss.as(:seconds) >> frames }
|
64
|
+
rule(:h_m) { hours >> separator >> minutes >> s_minutes.maybe }
|
65
|
+
rule(:h_m_s) { hours >> separator >> minutes >> separator >> seconds >> s_seconds.maybe }
|
66
|
+
rule(:small_h_m_s) { small_h.as(:hours) >> separator >> minutes >> separator >> seconds >> s_seconds.maybe }
|
67
|
+
rule(:m_s) { minutes >> separator >> seconds >> (s_minutes | s_seconds).maybe }
|
68
|
+
rule(:m_s_f) { minutes >> separator >> seconds_f >> s_seconds.maybe }
|
69
|
+
|
70
|
+
rule(:hr_min) { hours >> s_hours >> space? >> (minutes >> s_minutes.maybe).maybe }
|
71
|
+
rule(:hr_min_sec) { hours >> s_hours >> space? >> minutes >> s_minutes.maybe >> space? >> seconds >> s_seconds.maybe }
|
72
|
+
rule(:min_sec) { minutes >> s_minutes >> space? >> (seconds >> s_seconds.maybe).maybe }
|
73
|
+
|
74
|
+
rule(:unambiguous) { smpte | small_h_m_s | hr_min | hr_min_sec | min_sec }
|
75
|
+
rule(:ambiguous) { m_s_f | h_m_s | m_s | h_m | m | s }
|
76
|
+
rule(:exact) { unambiguous | ambiguous }
|
77
|
+
|
78
|
+
# approximate indicators
|
79
|
+
rule(:q) { str('?') }
|
80
|
+
rule(:ca) { str('c') >> str('a').maybe >> (str('.') | str(',')).maybe }
|
81
|
+
rule(:gt) { str('>').as(:gt) }
|
82
|
+
rule(:lt) { str('<').as(:lt) }
|
83
|
+
rule(:ish) { str('ish') }
|
84
|
+
rule(:s_approx) { str('approx') >> str('.').maybe }
|
85
|
+
|
86
|
+
# full matchers
|
87
|
+
rule(:approx) { space? >> (s_approx | q | ca | gt |lt | ish).as(:approximate) >> space?}
|
88
|
+
rule(:approximate_head) { approx >> exact }
|
89
|
+
rule(:approximate_tail) { exact >> approx }
|
90
|
+
rule(:approximate) { approximate_head | approximate_tail }
|
91
|
+
rule(:timecode) { approximate | exact }
|
92
|
+
|
93
|
+
# header tokens
|
94
|
+
rule(:trt) { str('TRT').as(:trt) >> space? }
|
95
|
+
rule(:colon_prefix) { str(':') }
|
96
|
+
|
97
|
+
rule(:duration) { (trt | colon_prefix).maybe >> timecode }
|
98
|
+
|
99
|
+
root :duration
|
100
|
+
end
|
data/lib/tc/version.rb
ADDED
data/lib/tc.rb
ADDED
@@ -0,0 +1,492 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'parslet/rig/rspec'
|
4
|
+
|
5
|
+
describe Tc::Duration do
|
6
|
+
let(:parser) { Tc::Duration.new }
|
7
|
+
|
8
|
+
context "integer" do
|
9
|
+
it "should consume '0'" do
|
10
|
+
parser.integer.should parse('0')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "mm" do
|
15
|
+
it "should consume '00'" do
|
16
|
+
parser.mm.should parse('00')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should consume '32'" do
|
20
|
+
parser.mm.should parse('32')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should consume '59'" do
|
24
|
+
parser.mm.should parse('59')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not consume '63'" do
|
28
|
+
parser.mm.should_not parse('63')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not consume '123'" do
|
32
|
+
parser.mm.should_not parse('123')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "min" do
|
37
|
+
it "should consume '00'" do
|
38
|
+
parser.min.should parse('00')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should consume '63'" do
|
42
|
+
parser.min.should parse('63')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should consume '123'" do
|
46
|
+
parser.min.should parse('123')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "minutes" do
|
51
|
+
end
|
52
|
+
|
53
|
+
context "s_minutes" do
|
54
|
+
it "should consume 'm'" do
|
55
|
+
parser.s_minutes.should parse('m')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should consume 'Min'" do
|
59
|
+
parser.s_minutes.should parse('Min')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should consume 'min.'" do
|
63
|
+
parser.s_minutes.should parse(' min.')
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should consume 'minutes'" do
|
67
|
+
parser.s_minutes.should parse(' minutes')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "m" do
|
72
|
+
it "should consume '53m'" do
|
73
|
+
parser.m.should parse('53m')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should consume '32 min." do
|
77
|
+
parser.m.should parse('32 min.')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should consume '120 minutes'" do
|
81
|
+
parser.m.should parse('120 minutes')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should consume '42 Minutes'" do
|
85
|
+
parser.m.should parse('42 Minutes')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should consume '58\''" do
|
89
|
+
parser.m.should parse('58\'')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "hh" do
|
94
|
+
end
|
95
|
+
|
96
|
+
context "small_h" do
|
97
|
+
it "should consume '01'" do
|
98
|
+
parser.small_h.should parse('01')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should consume '2'" do
|
102
|
+
parser.small_h.should parse('2')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not consume '12'" do
|
106
|
+
parser.small_h.should_not parse('12')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "small_h_m_s" do
|
111
|
+
it "should consume '01:09:26 s'" do
|
112
|
+
parser.small_h_m_s.should parse('01:09:26 s')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should not consume '275:00:00'" do
|
116
|
+
parser.small_h_m_s.should_not parse('275:00:00')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not consume '4:52:12'" do
|
120
|
+
parser.small_h_m_s.should_not parse('4:52:12')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 's_hours' do
|
125
|
+
it "should consume 'h'" do
|
126
|
+
parser.s_hours.should parse('h')
|
127
|
+
end
|
128
|
+
it "should consume 'hr'" do
|
129
|
+
parser.s_hours.should parse('hr')
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should consume 'H'" do
|
133
|
+
parser.s_hours.should parse('H')
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should consume 'hours'" do
|
137
|
+
parser.s_hours.should parse('hours')
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should consume 'hrs.'" do
|
141
|
+
parser.s_hours.should parse('hrs.')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "ss" do
|
146
|
+
it "should consume '00'" do
|
147
|
+
parser.ss.should parse('00')
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should consume '47'" do
|
151
|
+
parser.ss.should parse('47')
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should not consume '94'" do
|
155
|
+
parser.ss.should_not parse('94')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 's_seconds' do
|
160
|
+
it "should consume 's'" do
|
161
|
+
parser.s_seconds.should parse('s')
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should consume 'seconds'" do
|
165
|
+
parser.s_seconds.should parse('seconds')
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should consume 'sec'" do
|
169
|
+
parser.s_seconds.should parse('sec')
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should consume 'secs'" do
|
173
|
+
parser.s_seconds.should parse('secs')
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should consume 's.'" do
|
177
|
+
parser.s_seconds.should parse('s.')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "seconds" do
|
182
|
+
it "should consume '45'" do
|
183
|
+
parser.seconds.should parse('45')
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should consume '36.234'" do
|
187
|
+
parser.seconds.should parse('36.234')
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should consume '23:09'" do
|
191
|
+
parser.seconds.should parse('23:09')
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should consume '13;28'" do
|
195
|
+
parser.seconds.should parse('13;28')
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should consume '0.26875'" do
|
199
|
+
parser.seconds.should parse('0.26875')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'frames' do
|
204
|
+
it "should consume ';29'" do
|
205
|
+
parser.frames.should parse(';29')
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should consume ':12'" do
|
209
|
+
parser.frames.should parse(':12')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'smpte' do
|
214
|
+
it "should consume '01:02:03:04'" do
|
215
|
+
parser.smpte.should parse('01:02:03:04')
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should consume '01:08:59:29'" do
|
219
|
+
parser.smpte.should parse('01:08:59:29')
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should consume '00:56:57;00'" do
|
223
|
+
parser.smpte.should parse('00:56:57;00')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "h_m" do
|
228
|
+
it "should consume '1:23'" do
|
229
|
+
parser.h_m.should parse('1:23')
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should consume '04:32'" do
|
233
|
+
parser.h_m.should parse('04:32')
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "m_s" do
|
238
|
+
it "should consume '03:53'" do
|
239
|
+
parser.m_s.should parse('03:53')
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should consume '6:33'" do
|
243
|
+
parser.m_s.should parse('6:33')
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should consume '12:22:23'" do
|
247
|
+
parser.m_s.should parse('12:22:23')
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should consume '43:01;12'" do
|
251
|
+
parser.m_s.should parse('43:01;12')
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should consume '00:01.111'" do
|
255
|
+
parser.m_s.should parse('00:01.111')
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should consume '01:2.693'" do
|
259
|
+
parser.m_s.should parse('01:2.693')
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context "m_s_f" do
|
264
|
+
it "should not consume '03:53'" do
|
265
|
+
parser.m_s_f.should_not parse('03:53')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context "hr_min" do
|
270
|
+
it "should consume '4h'" do
|
271
|
+
parser.hr_min.should parse('4h')
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should consume '1hr 34min'" do
|
275
|
+
parser.hr_min.should parse('1hr 34min')
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should not consume '1m 34sec'" do
|
279
|
+
parser.hr_min.should_not parse('1m 34sec')
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context "min_sec" do
|
284
|
+
it "should consume '2m34s'" do
|
285
|
+
parser.min_sec.should parse('2m34s')
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should consume '22m 11s'" do
|
289
|
+
parser.min_sec.should parse('22m 11s')
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should consume '94m'" do
|
293
|
+
parser.min_sec.should parse('94m')
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "s" do
|
298
|
+
it "should consume '60s'" do
|
299
|
+
parser.s.should parse('60s')
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
context "exact" do
|
305
|
+
it "should parse '00:01'" do
|
306
|
+
parser.exact.should parse('00:01')
|
307
|
+
parsed = parser.exact.parse('00:01')
|
308
|
+
parsed[:minutes].should == '00'
|
309
|
+
parsed[:seconds].should == '01'
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should parse '00:01:02.043'" do
|
313
|
+
parser.exact.should parse('00:01:02.043')
|
314
|
+
parsed = parser.exact.parse('00:01:02.042')
|
315
|
+
|
316
|
+
parsed[:hours].should == '00'
|
317
|
+
parsed[:minutes].should == '01'
|
318
|
+
parsed[:seconds].should == '02.042'
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should parse '0.26875'" do
|
322
|
+
parser.exact.should parse('0.26875')
|
323
|
+
parsed = parser.exact.parse('0.26875')
|
324
|
+
|
325
|
+
parsed[:seconds].should == '0.26875'
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should parse '00:56:57;00'" do
|
329
|
+
parser.exact.should parse('00:56:57;00')
|
330
|
+
parsed = parser.exact.parse('00:56:57;00')
|
331
|
+
|
332
|
+
parsed[:hours].should == '00'
|
333
|
+
parsed[:minutes].should == '56'
|
334
|
+
parsed[:seconds].should == '57'
|
335
|
+
parsed.should include(:df)
|
336
|
+
parsed[:frames].should == '00'
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should parse '01:2.693'" do
|
340
|
+
parser.exact.should parse('01:2.693')
|
341
|
+
parsed = parser.exact.parse('01:2.693')
|
342
|
+
|
343
|
+
parsed[:minutes].should == '01'
|
344
|
+
parsed[:seconds].should == '2.693'
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should parse '20:00m'" do
|
348
|
+
parser.exact.should parse('20:00m')
|
349
|
+
parsed = parser.exact.parse('20:00m')
|
350
|
+
|
351
|
+
parsed[:minutes].should == '20'
|
352
|
+
parsed[:seconds].should == '00'
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should parse '21:44.450'" do
|
356
|
+
parser.exact.should parse('21:44.450')
|
357
|
+
parsed = parser.exact.parse('21:44.450')
|
358
|
+
|
359
|
+
parsed[:minutes].should == '21'
|
360
|
+
parsed[:seconds].should == '44.450'
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should parse '227min.'" do
|
364
|
+
parser.exact.should parse('227min.')
|
365
|
+
parsed = parser.exact.parse('227min.')
|
366
|
+
|
367
|
+
parsed[:minutes].should == '227'
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should parse '229:00'" do
|
371
|
+
parser.exact.should parse('229:00')
|
372
|
+
parsed = parser.exact.parse('229:00')
|
373
|
+
parsed[:minutes].should == '229'
|
374
|
+
parsed[:seconds].should == '00'
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should parse '22m 11s'" do
|
378
|
+
parser.exact.should parse('22m 11s')
|
379
|
+
parsed = parser.exact.parse('22m 11s')
|
380
|
+
parsed[:minutes].should == '22'
|
381
|
+
parsed[:seconds].should == '11'
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should parse '25:04:00'" do
|
385
|
+
parser.exact.should parse('25:04:00')
|
386
|
+
parsed = parser.exact.parse('25:04:00')
|
387
|
+
|
388
|
+
parsed[:minutes].should == '25'
|
389
|
+
parsed[:seconds].should == '04'
|
390
|
+
parsed[:frames].should == '00'
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should parse '29:28'" do
|
394
|
+
parser.exact.should parse('29:28')
|
395
|
+
parsed = parser.exact.parse('29:28')
|
396
|
+
parsed[:minutes].should == '29'
|
397
|
+
parsed[:seconds].should == '28'
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should parse '5100.0'" do
|
401
|
+
parser.exact.should parse('5100.0')
|
402
|
+
parsed = parser.exact.parse('5100.0')
|
403
|
+
|
404
|
+
parsed[:seconds].should == '5100.0'
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should parse '120'" do
|
408
|
+
parser.exact.should parse('120')
|
409
|
+
parsed = parser.exact.parse('120')
|
410
|
+
parsed[:minutes].should == '120'
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should parse '58\''" do
|
414
|
+
parser.exact.should parse("58'")
|
415
|
+
parsed = parser.exact.parse("58'")
|
416
|
+
|
417
|
+
parsed[:minutes].should == "58"
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should parse 4h" do
|
421
|
+
parser.exact.should parse('4h')
|
422
|
+
parsed = parser.exact.parse('4h')
|
423
|
+
|
424
|
+
parsed[:hours].should == '4'
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should parse '01:09:26 s'" do
|
428
|
+
parser.exact.should parse('01:09:26 s')
|
429
|
+
parsed = parser.exact.parse('01:09:26 s')
|
430
|
+
|
431
|
+
parsed[:hours].should == '01'
|
432
|
+
parsed[:minutes].should == '09'
|
433
|
+
parsed[:seconds].should == '26'
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context "approximate" do
|
438
|
+
it "should consume '00:00:00?'" do
|
439
|
+
parser.approximate.should parse('00:00:00?')
|
440
|
+
end
|
441
|
+
|
442
|
+
it "should consume '8ish'" do
|
443
|
+
parser.approximate.should parse('8ish')
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should consume '<1hr'" do
|
447
|
+
parser.approximate.should parse('<1hr')
|
448
|
+
|
449
|
+
parsed = parser.approximate.parse('<1hr')
|
450
|
+
parsed.should include(:approximate)
|
451
|
+
parsed[:approximate].should include(:lt)
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should consume 'ca. 77m'" do
|
455
|
+
parser.approximate.should parse('ca. 77m')
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should consume 'approx. 32min'" do
|
459
|
+
parser.approximate.should parse('approx. 32min')
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
context "timecode" do
|
464
|
+
it "should parse '01:09:26 s'" do
|
465
|
+
parser.timecode.should parse('01:09:26 s')
|
466
|
+
parsed = parser.timecode.parse('01:09:26 s')
|
467
|
+
|
468
|
+
parsed[:hours].should == '01'
|
469
|
+
parsed[:minutes].should == '09'
|
470
|
+
parsed[:seconds].should == '26'
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should parse '22:11?'" do
|
474
|
+
parser.timecode.should parse('22:11?')
|
475
|
+
parsed = parser.timecode.parse('22:11?')
|
476
|
+
|
477
|
+
parsed[:minutes].should == '22'
|
478
|
+
parsed[:seconds].should == '11'
|
479
|
+
parsed.should include(:approximate)
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
context "duration" do
|
484
|
+
it "should consume 'TRT 25:57'" do
|
485
|
+
parser.duration.should parse('TRT 25:57')
|
486
|
+
end
|
487
|
+
|
488
|
+
it "should consume ':00:26:30'" do
|
489
|
+
parser.duration.should parse(':00:26:30')
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tc.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tc"
|
7
|
+
s.version = Tc::VERSION
|
8
|
+
s.authors = ["Chris Beer"]
|
9
|
+
s.email = ["chris_beer@wgbh.org"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Timecode parsing}
|
12
|
+
s.description = %q{Timecode parsing}
|
13
|
+
|
14
|
+
s.rubyforge_project = "tc"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "parslet"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Beer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-10 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: parslet
|
17
|
+
requirement: &2161225380 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2161225380
|
26
|
+
description: Timecode parsing
|
27
|
+
email:
|
28
|
+
- chris_beer@wgbh.org
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/tc.rb
|
39
|
+
- lib/tc/duration.rb
|
40
|
+
- lib/tc/version.rb
|
41
|
+
- spec/lib/tc_duration_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- tc.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project: tc
|
65
|
+
rubygems_version: 1.6.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Timecode parsing
|
69
|
+
test_files:
|
70
|
+
- spec/lib/tc_duration_spec.rb
|
71
|
+
- spec/spec_helper.rb
|