srt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/srt/file.rb +1 -1
- data/lib/srt/line.rb +4 -0
- data/lib/srt/parser.rb +1 -1
- data/lib/srt/version.rb +1 -1
- data/spec/file_spec.rb +82 -82
- data/spec/line_spec.rb +2 -2
- data/spec/parser_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2FlZWEzMGIwYjhjZjg5NmFkYjM1YjBlMGYyNTA0YTAzMTVhNWNmMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWEzYTM3YjJlMDA1YjUzNzYzMmQ4ZWFjNjM2NzRhM2VkZjAwZjRhNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTU1NWFiNWFiMGMyODM0OWMzMTdhZTIxNGI0NTc5NjIwMjJlZDk2Zjc0OTY5
|
10
|
+
ZmI3Njk2YmUxNTNkOWJlMjUxNDE1MzdiZjQwMWNmMzg0ZWU2MDAzZDU5MDY2
|
11
|
+
NzNjM2IzMGMyMDI4Yjc4YmJiM2E4Y2Q1YzcwZTYxODBlZWE5NDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGVmZDNhOTYwYjYxZGMzNTc3YzQ0YjliODhjNTVlODliMTU3MzAzMDA1YTE5
|
14
|
+
MmJjOGNiMTZlYTc3NTc3MDI4YjZlMDZiZjI3MWQwMTgwZDZiOWFmZTE5ZjYy
|
15
|
+
MWJiY2I0MTJkODYxNjFlYjcwY2I4ODM3MjJjMjQ4NDczMGRkYTc=
|
data/lib/srt/file.rb
CHANGED
@@ -209,7 +209,7 @@ module SRT
|
|
209
209
|
end
|
210
210
|
|
211
211
|
def to_s(time_str_function=:time_str)
|
212
|
-
lines.map { |l|
|
212
|
+
lines.map { |l| l.to_s(time_str_function) }.join("\n")
|
213
213
|
end
|
214
214
|
|
215
215
|
def to_webvtt
|
data/lib/srt/line.rb
CHANGED
@@ -39,5 +39,9 @@ module SRT
|
|
39
39
|
def webvtt_time_str
|
40
40
|
time_str(".")
|
41
41
|
end
|
42
|
+
|
43
|
+
def to_s(time_str_function=:time_str)
|
44
|
+
[sequence, (display_coordinates ? send(time_str_function) + display_coordinates : send(time_str_function)), text, ''].flatten.join("\n")
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
data/lib/srt/parser.rb
CHANGED
@@ -12,7 +12,7 @@ module SRT
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def timecode(timecode_string)
|
15
|
-
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+)
|
15
|
+
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+)[,.](?<ms>\d+)/)
|
16
16
|
mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["ms"]}".to_f : nil
|
17
17
|
end
|
18
18
|
|
data/lib/srt/version.rb
CHANGED
data/spec/file_spec.rb
CHANGED
@@ -5,14 +5,14 @@ describe SRT::File do
|
|
5
5
|
describe '#parse' do
|
6
6
|
context "parsing with debug true" do
|
7
7
|
it "should be verbose when failing" do
|
8
|
-
$stderr.
|
9
|
-
SRT::File.parse(File.open("./spec/fixtures/invalid.srt"), debug: true).errors.
|
8
|
+
expect($stderr).to receive(:puts).once
|
9
|
+
expect(SRT::File.parse(File.open("./spec/fixtures/invalid.srt"), debug: true).errors).not_to be_empty
|
10
10
|
end
|
11
11
|
end
|
12
12
|
context "parsing with debug false" do
|
13
13
|
it "should raise exception silently" do
|
14
|
-
$stderr.
|
15
|
-
SRT::File.parse(File.open("./spec/fixtures/invalid.srt")).errors.
|
14
|
+
expect($stderr).not_to receive(:puts)
|
15
|
+
expect(SRT::File.parse(File.open("./spec/fixtures/invalid.srt")).errors).not_to be_empty
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -20,39 +20,39 @@ describe SRT::File do
|
|
20
20
|
shared_examples_for "an SRT file" do
|
21
21
|
context "when parsing a properly formatted BSG SRT file" do
|
22
22
|
it "should return an SRT::File" do
|
23
|
-
subject.class.
|
23
|
+
expect(subject.class).to eq(SRT::File)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should have 600 lines" do
|
27
|
-
subject.lines.size.
|
27
|
+
expect(subject.lines.size).to eq(600)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should have no errors" do
|
31
|
-
subject.errors.
|
31
|
+
expect(subject.errors).to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should have the expected sequence number on the first subtitle" do
|
35
|
-
subject.lines.first.sequence.
|
35
|
+
expect(subject.lines.first.sequence).to eq(1)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should have the expected timecodes on the first subtitle" do
|
39
|
-
subject.lines.first.time_str.
|
39
|
+
expect(subject.lines.first.time_str).to eq("00:00:02,110 --> 00:00:04,578")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should have the expected text on the first subtitle" do
|
43
|
-
subject.lines.first.text.
|
43
|
+
expect(subject.lines.first.text).to eq(["<i>(male narrator) Previously", "on Battlestar Galactica.</i>"])
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should have the expected sequence number on the last subtitle" do
|
47
|
-
subject.lines.last.sequence.
|
47
|
+
expect(subject.lines.last.sequence).to eq(600)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should have the expected timecodes on the last subtitle" do
|
51
|
-
subject.lines.last.time_str.
|
51
|
+
expect(subject.lines.last.time_str).to eq("00:43:26,808 --> 00:43:28,139")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should have the expected text on the last subtitle" do
|
55
|
-
subject.lines.last.text.
|
55
|
+
expect(subject.lines.last.text).to eq(["Thank you."])
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -62,15 +62,15 @@ describe SRT::File do
|
|
62
62
|
let(:file) { SRT::File.parse(File.open("./spec/fixtures/wotw-dubious.srt")) }
|
63
63
|
|
64
64
|
it "should parse" do
|
65
|
-
file.class.
|
65
|
+
expect(file.class).to eq(SRT::File)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should have 1123 lines" do
|
69
|
-
file.lines.size.
|
69
|
+
expect(file.lines.size).to eq(1123)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should have no errors" do
|
73
|
-
file.errors.
|
73
|
+
expect(file.errors).to be_empty
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,23 +78,23 @@ describe SRT::File do
|
|
78
78
|
let(:file) { SRT::File.parse(File.open("./spec/fixtures/coordinates-dummy.srt")) }
|
79
79
|
|
80
80
|
it "should return an SRT::File" do
|
81
|
-
file.class.
|
81
|
+
expect(file.class).to eq(SRT::File)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should have 3 lines" do
|
85
|
-
file.lines.size.
|
85
|
+
expect(file.lines.size).to eq(3)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should have no errors" do
|
89
|
-
file.errors.
|
89
|
+
expect(file.errors).to be_empty
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should have the expected display coordinates on the first subtitle" do
|
93
|
-
file.lines.first.display_coordinates.
|
93
|
+
expect(file.lines.first.display_coordinates).to eq("X1:100 X2:600 Y1:1 Y2:4")
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should have the expected display coordinates on the last subtitle" do
|
97
|
-
file.lines.last.display_coordinates.
|
97
|
+
expect(file.lines.last.display_coordinates).to eq("X1:1 X2:333 Y1:50 Y2:29")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -118,19 +118,19 @@ describe SRT::File do
|
|
118
118
|
before { part1.append({ "00:53:57,241" => part2 }) }
|
119
119
|
|
120
120
|
it "should have grown to 808 subtitles" do
|
121
|
-
part1.lines.length.
|
121
|
+
expect(part1.lines.length).to eq(808)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should have appended subtitles starting with sequence number 448" do
|
125
|
-
part1.lines[447].sequence.
|
125
|
+
expect(part1.lines[447].sequence).to eq(448)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should have appended subtitles ending with sequence number 808" do
|
129
|
-
part1.lines.last.sequence.
|
129
|
+
expect(part1.lines.last.sequence).to eq(808)
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should have appended subtitles relatively from 00:53:57,241" do
|
133
|
-
part1.lines[447].time_str.
|
133
|
+
expect(part1.lines[447].time_str).to eq("00:54:02,152 --> 00:54:04,204")
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -138,7 +138,7 @@ describe SRT::File do
|
|
138
138
|
before { part1.append({ "+7.241s" => part2 }) }
|
139
139
|
|
140
140
|
it "should have appended subtitles relatively from +7.241s after the previously last subtitle" do
|
141
|
-
part1.lines[447].time_str.
|
141
|
+
expect(part1.lines[447].time_str).to eq("00:54:02,283 --> 00:54:04,335")
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
@@ -152,29 +152,29 @@ describe SRT::File do
|
|
152
152
|
let(:result) { file.split( :at => "00:19:24,500" ) }
|
153
153
|
|
154
154
|
it "should return an array containing two SRT::File instances" do
|
155
|
-
result.length.
|
156
|
-
result[0].class.
|
157
|
-
result[1].class.
|
155
|
+
expect(result.length).to eq(2)
|
156
|
+
expect(result[0].class).to eq(SRT::File)
|
157
|
+
expect(result[1].class).to eq(SRT::File)
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should include a subtitle that overlaps a splitting point in the first file" do
|
161
|
-
result[0].lines.last.text.
|
161
|
+
expect(result[0].lines.last.text).to eq(["I'll see you guys in combat."])
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should make an overlapping subtitle end at the splitting point in the first file" do
|
165
|
-
result[0].lines.last.time_str.
|
165
|
+
expect(result[0].lines.last.time_str).to eq("00:19:23,901 --> 00:19:24,500")
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should include a subtitle that overlaps a splitting point in the second file as well" do
|
169
|
-
result[1].lines.first.text.
|
169
|
+
expect(result[1].lines.first.text).to eq(["I'll see you guys in combat."])
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should make an overlapping subtitle remain at the beginning in the second file" do
|
173
|
-
result[1].lines.first.time_str.
|
173
|
+
expect(result[1].lines.first.time_str).to eq("00:00:00,000 --> 00:00:01,528")
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should shift back all timecodes of the second file relative to the new file beginning" do
|
177
|
-
result[1].lines[1].time_str.
|
177
|
+
expect(result[1].lines[1].time_str).to eq("00:00:01,737 --> 00:00:03,466")
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
@@ -182,29 +182,29 @@ describe SRT::File do
|
|
182
182
|
let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
|
183
183
|
|
184
184
|
it "should return an array containing two SRT::File instances" do
|
185
|
-
result.length.
|
186
|
-
result[0].class.
|
187
|
-
result[1].class.
|
185
|
+
expect(result.length).to eq(2)
|
186
|
+
expect(result[0].class).to eq(SRT::File)
|
187
|
+
expect(result[1].class).to eq(SRT::File)
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should include a subtitle that overlaps a splitting point in the first file" do
|
191
|
-
result[0].lines.last.text.
|
191
|
+
expect(result[0].lines.last.text).to eq(["I'll see you guys in combat."])
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should not make an overlapping subtitle end at the splitting point in the first file" do
|
195
|
-
result[0].lines.last.time_str.
|
195
|
+
expect(result[0].lines.last.time_str).to eq("00:19:23,901 --> 00:19:26,028")
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should include a subtitle that overlaps a splitting point in the second file as well" do
|
199
|
-
result[1].lines.first.text.
|
199
|
+
expect(result[1].lines.first.text).to eq(["I'll see you guys in combat."])
|
200
200
|
end
|
201
201
|
|
202
202
|
it "should not make an overlapping subtitle remain at the beginning in the second file" do
|
203
|
-
result[1].lines.first.time_str.
|
203
|
+
expect(result[1].lines.first.time_str).to eq("00:19:23,901 --> 00:19:26,028")
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should not shift back timecodes of the second file relative to the new file beginning" do
|
207
|
-
result[1].lines[1].time_str.
|
207
|
+
expect(result[1].lines[1].time_str).to eq("00:19:26,237 --> 00:19:27,966")
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -212,31 +212,31 @@ describe SRT::File do
|
|
212
212
|
let(:result) { file.split( :at => ["00:15:00,000", "00:30:00,000"] ) }
|
213
213
|
|
214
214
|
it "should return an array containing three SRT::File instances" do
|
215
|
-
result.length.
|
216
|
-
result[0].class.
|
217
|
-
result[1].class.
|
218
|
-
result[2].class.
|
215
|
+
expect(result.length).to eq(3)
|
216
|
+
expect(result[0].class).to eq(SRT::File)
|
217
|
+
expect(result[1].class).to eq(SRT::File)
|
218
|
+
expect(result[2].class).to eq(SRT::File)
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should let subtitles start at sequence number #1 in all three files" do
|
222
|
-
result[0].lines.first.sequence.
|
223
|
-
result[1].lines.first.sequence.
|
224
|
-
result[2].lines.first.sequence.
|
222
|
+
expect(result[0].lines.first.sequence).to eq(1)
|
223
|
+
expect(result[1].lines.first.sequence).to eq(1)
|
224
|
+
expect(result[2].lines.first.sequence).to eq(1)
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should put 176 subtitles in the first file" do
|
228
|
-
result[0].lines.length.
|
229
|
-
result[0].lines.last.sequence.
|
228
|
+
expect(result[0].lines.length).to eq(176)
|
229
|
+
expect(result[0].lines.last.sequence).to eq(176)
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should put 213 subtitles in the second file" do
|
233
|
-
result[1].lines.length.
|
234
|
-
result[1].lines.last.sequence.
|
233
|
+
expect(result[1].lines.length).to eq(213)
|
234
|
+
expect(result[1].lines.last.sequence).to eq(213)
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should put 212 subtitles in the third file" do
|
238
|
-
result[2].lines.length.
|
239
|
-
result[2].lines.last.sequence.
|
238
|
+
expect(result[2].lines.length).to eq(212)
|
239
|
+
expect(result[2].lines.last.sequence).to eq(212)
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
@@ -244,9 +244,9 @@ describe SRT::File do
|
|
244
244
|
let(:result) { file.split( :at => "00:19:24,500", :every => "00:00:01,000" ) }
|
245
245
|
|
246
246
|
it "should return an array containing two SRT::File instances, ignoring :every" do
|
247
|
-
result.length.
|
248
|
-
result[0].class.
|
249
|
-
result[1].class.
|
247
|
+
expect(result.length).to eq(2)
|
248
|
+
expect(result[0].class).to eq(SRT::File)
|
249
|
+
expect(result[1].class).to eq(SRT::File)
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
@@ -254,9 +254,9 @@ describe SRT::File do
|
|
254
254
|
let(:result) { file.split( :every => "00:05:00,000" ) }
|
255
255
|
|
256
256
|
it "should return an array containing nine SRT::File instances" do
|
257
|
-
result.length.
|
257
|
+
expect(result.length).to eq(9)
|
258
258
|
(0...result.count).each do |n|
|
259
|
-
result[n].class.
|
259
|
+
expect(result[n].class).to eq(SRT::File)
|
260
260
|
end
|
261
261
|
end
|
262
262
|
end
|
@@ -265,8 +265,8 @@ describe SRT::File do
|
|
265
265
|
let(:result) { file.split( :at => "00:19:24,500", :renumber => false ) }
|
266
266
|
|
267
267
|
it "sequence for the last line of first part should be the sequence for the first line of second part" do
|
268
|
-
result[0].lines.last.text.
|
269
|
-
result[0].lines.last.sequence.
|
268
|
+
expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
|
269
|
+
expect(result[0].lines.last.sequence).to eq(result[1].lines.first.sequence)
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
@@ -274,12 +274,12 @@ describe SRT::File do
|
|
274
274
|
let(:result) { file.split( :at => "00:19:24,500", :renumber => true ) }
|
275
275
|
|
276
276
|
it "first line of second part's number should be one" do
|
277
|
-
result[1].lines.first.sequence.
|
277
|
+
expect(result[1].lines.first.sequence).to eq(1)
|
278
278
|
end
|
279
279
|
|
280
280
|
it "sequence for the last line of first part should have different number than the sequence for the first line of second part" do
|
281
|
-
result[0].lines.last.text.
|
282
|
-
result[0].lines.last.sequence.
|
281
|
+
expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
|
282
|
+
expect(result[0].lines.last.sequence).not_to eq(result[1].lines.first.sequence)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -287,8 +287,8 @@ describe SRT::File do
|
|
287
287
|
let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
|
288
288
|
|
289
289
|
it "time for last line of first part should be the time for first line of second part" do
|
290
|
-
result[0].lines.last.text.
|
291
|
-
result[0].lines.last.time_str.
|
290
|
+
expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
|
291
|
+
expect(result[0].lines.last.time_str).to eq(result[1].lines.first.time_str)
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
@@ -296,12 +296,12 @@ describe SRT::File do
|
|
296
296
|
let(:result) { file.split( :at => "00:19:24,500", :timeshift => true ) }
|
297
297
|
|
298
298
|
it "start_time of first line in second part should be 0" do
|
299
|
-
result[1].lines.first.start_time.
|
299
|
+
expect(result[1].lines.first.start_time).to eq(0)
|
300
300
|
end
|
301
301
|
|
302
302
|
it "time for last line of first part should not be the time for first line of second part" do
|
303
|
-
result[0].lines.last.text.
|
304
|
-
result[0].lines.last.time_str.
|
303
|
+
expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
|
304
|
+
expect(result[0].lines.last.time_str).not_to eq(result[1].lines.first.time_str)
|
305
305
|
end
|
306
306
|
end
|
307
307
|
end
|
@@ -315,11 +315,11 @@ describe SRT::File do
|
|
315
315
|
before { file.timeshift({ :all => "+2.5s" }) }
|
316
316
|
|
317
317
|
it "should have timecodes shifted forward by 2.5s for subtitle #24" do
|
318
|
-
file.lines[23].time_str.
|
318
|
+
expect(file.lines[23].time_str).to eq("00:01:59,291 --> 00:02:00,815")
|
319
319
|
end
|
320
320
|
|
321
321
|
it "should have timecodes shifted forward by 2.5s for subtitle #43" do
|
322
|
-
file.lines[42].time_str.
|
322
|
+
expect(file.lines[42].time_str).to eq("00:03:46,164 --> 00:03:47,631")
|
323
323
|
end
|
324
324
|
end
|
325
325
|
|
@@ -327,11 +327,11 @@ describe SRT::File do
|
|
327
327
|
before { file.timeshift({ "25fps" => "23.976fps" }) }
|
328
328
|
|
329
329
|
it "should have correctly scaled timecodes for subtitle #24" do
|
330
|
-
file.lines[23].time_str.
|
330
|
+
expect(file.lines[23].time_str).to eq("00:01:52,007 --> 00:01:53,469")
|
331
331
|
end
|
332
332
|
|
333
333
|
it "should have correctly scaled timecodes for subtitle #43" do
|
334
|
-
file.lines[42].time_str.
|
334
|
+
expect(file.lines[42].time_str).to eq("00:03:34,503 --> 00:03:35,910")
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
@@ -339,11 +339,11 @@ describe SRT::File do
|
|
339
339
|
before { file.timeshift({ "#24" => "00:03:53,582", "#42" => "00:04:24,656" }) }
|
340
340
|
|
341
341
|
it "should have shifted timecodes for subtitle #24" do
|
342
|
-
file.lines[23].time_str.
|
342
|
+
expect(file.lines[23].time_str).to eq("00:03:53,582 --> 00:03:54,042")
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should have differently shifted timecodes for subtitle #43" do
|
346
|
-
file.lines[41].time_str.
|
346
|
+
expect(file.lines[41].time_str).to eq("00:04:24,656 --> 00:04:25,298")
|
347
347
|
end
|
348
348
|
end
|
349
349
|
|
@@ -351,11 +351,11 @@ describe SRT::File do
|
|
351
351
|
before { file.timeshift({ 180 => "+1s", 264 => "+1.5s" }) }
|
352
352
|
|
353
353
|
it "should have shifted by +1s at 180 seconds" do
|
354
|
-
file.lines[23].time_str.
|
354
|
+
expect(file.lines[23].time_str).to eq("00:01:57,415 --> 00:01:58,948")
|
355
355
|
end
|
356
356
|
|
357
357
|
it "should have shifted by +1.5s at 264 seconds" do
|
358
|
-
file.lines[41].time_str.
|
358
|
+
expect(file.lines[41].time_str).to eq("00:03:40,997 --> 00:03:43,136")
|
359
359
|
end
|
360
360
|
end
|
361
361
|
end
|
@@ -367,7 +367,7 @@ describe SRT::File do
|
|
367
367
|
before { file.timeshift({ :all => "-2.7m" }) }
|
368
368
|
|
369
369
|
it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
|
370
|
-
file.lines.size.
|
370
|
+
expect(file.lines.size).to eq(1107)
|
371
371
|
end
|
372
372
|
end
|
373
373
|
|
@@ -375,7 +375,7 @@ describe SRT::File do
|
|
375
375
|
before { file.timeshift({ "00:03:25,430" => "00:00:44,200", "01:49:29,980" => "01:46:35,600" }) }
|
376
376
|
|
377
377
|
it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
|
378
|
-
file.lines.size.
|
378
|
+
expect(file.lines.size).to eq(1107)
|
379
379
|
end
|
380
380
|
end
|
381
381
|
end
|
@@ -402,7 +402,7 @@ you're a machine.
|
|
402
402
|
00:00:07,014 --> 00:00:08,003
|
403
403
|
The robot.
|
404
404
|
END
|
405
|
-
file.to_s.
|
405
|
+
expect(file.to_s).to eq(OUTPUT)
|
406
406
|
end
|
407
407
|
end
|
408
408
|
end
|
@@ -432,7 +432,7 @@ you're a machine.
|
|
432
432
|
00:00:07.014 --> 00:00:08.003
|
433
433
|
The robot.
|
434
434
|
END
|
435
|
-
file.to_webvtt.
|
435
|
+
expect(file.to_webvtt).to eq(OUTPUT_WEBVTT)
|
436
436
|
end
|
437
437
|
end
|
438
438
|
end
|
data/spec/line_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe SRT::Line do
|
|
6
6
|
let(:line) { SRT::Line.new }
|
7
7
|
|
8
8
|
it "should create an empty subtitle" do
|
9
|
-
line.
|
9
|
+
expect(line).to be_empty
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -19,7 +19,7 @@ describe SRT::Line do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should produce timecodes that match the internal float values" do
|
22
|
-
line.time_str.
|
22
|
+
expect(line.time_str).to eq("00:03:44,200 --> 00:04:04,578")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -6,33 +6,33 @@ describe SRT::Parser do
|
|
6
6
|
|
7
7
|
describe ".id" do
|
8
8
|
it "should convert the id string (#[id]) to an int representing the sequence number" do
|
9
|
-
subject.id("#317").
|
9
|
+
expect(subject.id("#317")).to eq(317)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe ".timecode" do
|
14
14
|
it "should convert the SRT timecode format to a float representing seconds" do
|
15
|
-
subject.timecode("01:03:44,200").
|
15
|
+
expect(subject.timecode("01:03:44,200")).to eq(3824.2)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe ".timespan" do
|
20
20
|
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
21
|
-
subject.timespan("-3.5m").
|
21
|
+
expect(subject.timespan("-3.5m")).to eq(-210)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
25
|
-
subject.timespan("-1s").
|
25
|
+
expect(subject.timespan("-1s")).to eq(-1)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
29
|
-
subject.timespan("100ms").
|
29
|
+
expect(subject.timespan("100ms")).to eq(0.1)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe ".parse_framerate" do
|
34
34
|
it "should convert a framerate string ([number]fps) to a float representing seconds" do
|
35
|
-
subject.framerate("23.976fps").
|
35
|
+
expect(subject.framerate("23.976fps")).to eq(23.976)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|