subtitle_converter 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/subtitle_converter/stl_reader.rb +9 -12
- data/lib/subtitle_converter/sub_rib_writer.rb +1 -1
- data/lib/subtitle_converter/subtitle_convertor.rb +5 -5
- data/lib/subtitle_converter/version.rb +2 -2
- data/spec/assets/IDEO_subtitles_en.txt +1 -1
- data/spec/stl_reader_spec.rb +5 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191363dc27d70fda96cacb9df2c059f1e31a47fa
|
4
|
+
data.tar.gz: fb017b62cf4898b54d36929c868c0ee64f11e9f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f623e35c1d7a8cbb8b49be1f19a8f1a663fb3d6bfb54e295776a52bd44777974fc594030ae021de4c0fd579b2e43f39fe9116f24f180bd06a34036e62929f18
|
7
|
+
data.tar.gz: 087ba6ef0a6911ebc94d53fa573e5b4e066743877f03758bf7cfee8dd273f849b836899ddf0c45430f3319b8441774d22ac3a77c2d3fb8ee60832b1afb468978
|
data/README.md
CHANGED
@@ -1,29 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class STLReader
|
4
|
+
|
4
5
|
attr_reader :stl_sub_title_lines
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
@stl_sub_title_lines = []
|
7
9
|
end
|
8
10
|
|
9
11
|
def import_stl_content(file_name)
|
10
|
-
|
11
|
-
|
12
|
-
parse_srt_content(file)
|
13
|
-
file.close
|
14
|
-
rescue SystemCallError
|
15
|
-
puts "File not found"
|
16
|
-
end
|
12
|
+
content = File.read(file_name)
|
13
|
+
parse_stl_content(content)
|
17
14
|
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
@stl_sub_title_lines =
|
16
|
+
def parse_stl_content(content)
|
17
|
+
|
18
|
+
@stl_sub_title_lines = content.lines.select { |line|
|
22
19
|
line =~ /\d{2}(:[0-5]\d){3}\s+,\s+\d{2}(:[0-5]\d){3}\s+,\s+.*/
|
23
|
-
}.map{|line|
|
20
|
+
}.map { |line|
|
24
21
|
line.gsub!(", \t", ",\t")
|
25
22
|
line.gsub!("\t ,", "\t,")
|
26
23
|
line.split("\t,\t").map(&:strip).join("#")
|
27
24
|
}
|
28
25
|
end
|
29
|
-
end
|
26
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class SubtitleConvertor
|
4
|
-
|
4
|
+
|
5
5
|
def from(filename)
|
6
6
|
@reader = STLReader.new
|
7
7
|
@reader.import_stl_content(filename)
|
8
8
|
self
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def to(filename)
|
12
12
|
@writer = SubRibWriter.new
|
13
13
|
@output_file = filename
|
14
14
|
self
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def convert
|
18
18
|
@writer.parse_stl_lines(@reader.stl_sub_title_lines)
|
19
19
|
@writer.to_file(@output_file)
|
20
20
|
end
|
21
|
-
|
22
|
-
end
|
21
|
+
|
22
|
+
end
|
@@ -151,4 +151,4 @@ $TapeOffset = TRUE
|
|
151
151
|
00:07:56:18 , 00:08:00:25 , a belief that chaos can be constructive and teamwork
|
152
152
|
00:08:00:26 , 00:08:02:26 , a great deal of teamwork
|
153
153
|
00:08:02:27 , 00:08:07:08 , And these are the recipe for how innovation takes place
|
154
|
-
00:08:07:09 , 00:08:11:24 , This is Jack Smith for Nightline, Palo Alto, California
|
154
|
+
00:08:07:09 , 00:08:11:24 , This is Jack Smith for Nightline, Palo Alto, California
|
data/spec/stl_reader_spec.rb
CHANGED
@@ -2,10 +2,13 @@
|
|
2
2
|
require 'subtitle_converter'
|
3
3
|
|
4
4
|
describe STLReader do
|
5
|
+
|
5
6
|
describe "read stl file and read it content into memory" do
|
7
|
+
|
6
8
|
let(:stl_reader) { STLReader.new }
|
9
|
+
|
7
10
|
let(:data) {
|
8
|
-
"00:00:03:15\t,\t00:00:05:26\t,\tTonight, The Deep Dive
|
11
|
+
"00:00:03:15\t,\t00:00:05:26\t,\tTonight, The Deep Dive.
|
9
12
|
00:00:05:27\t,\t00:00:10:01\t,\tOne company's secret weapon for innovation"
|
10
13
|
}
|
11
14
|
|
@@ -14,14 +17,9 @@ describe STLReader do
|
|
14
17
|
]}
|
15
18
|
|
16
19
|
it "should open STL file and import content to 'srt_sub_title_lines'" do
|
17
|
-
File.stub(:
|
20
|
+
File.stub(:read).with("file_name") { data }
|
18
21
|
stl_reader.import_stl_content("file_name")
|
19
22
|
stl_reader.stl_sub_title_lines.should eq(result)
|
20
23
|
end
|
21
|
-
|
22
|
-
it "should inform 'file not found' in case target file doesn't exist" do
|
23
|
-
stl_reader.should_receive(:puts).with("File not found")
|
24
|
-
stl_reader.import_stl_content("not_existing_file")
|
25
|
-
end
|
26
24
|
end
|
27
25
|
end
|