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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 685a9eaefbcb8091dba91d86aa9909b9f38fa2bc
4
- data.tar.gz: f8ee8b7c0be0be9dd4d0d19bed3f4e2983428ccf
3
+ metadata.gz: 191363dc27d70fda96cacb9df2c059f1e31a47fa
4
+ data.tar.gz: fb017b62cf4898b54d36929c868c0ee64f11e9f2
5
5
  SHA512:
6
- metadata.gz: c329fee4d3006fe70bab24dc85725b3fc41cf55647deb6f9970d539a7ebb07dfd6a417ecf1037f3693997ea402aee2fc885478a7c681e9d6f902b42c1fe2236c
7
- data.tar.gz: 1d8719e7c9e2ad734d13acb21cd44400f5df6dac1449df818bce61eeccd68d26a9f2f32247c650535b5504f108a1906cac318281543307390ae343b490064a9d
6
+ metadata.gz: 3f623e35c1d7a8cbb8b49be1f19a8f1a663fb3d6bfb54e295776a52bd44777974fc594030ae021de4c0fd579b2e43f39fe9116f24f180bd06a34036e62929f18
7
+ data.tar.gz: 087ba6ef0a6911ebc94d53fa573e5b4e066743877f03758bf7cfee8dd273f849b836899ddf0c45430f3319b8441774d22ac3a77c2d3fb8ee60832b1afb468978
data/README.md CHANGED
@@ -14,4 +14,4 @@ http://wiki.videolan.org/SubRip
14
14
 
15
15
  *** Installation
16
16
 
17
- gem install subtitle_convertor
17
+ gem install subtitle_converter
@@ -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
- begin
11
- file =File.open(file_name, "r")
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
- private
20
- def parse_srt_content(file)
21
- @stl_sub_title_lines = file.select{|line|
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
@@ -24,7 +24,7 @@ class SubRibWriter
24
24
  end
25
25
 
26
26
  def to_file(filename)
27
- file = File.open filename, "w" do |file|
27
+ File.open filename, "w" do |file|
28
28
  subrib_sub_title_lines.each do |line|
29
29
  file.puts line
30
30
  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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SubtitleConverterVersion
3
- VERSION = "0.0.3"
4
- end
3
+ VERSION = "0.0.4"
4
+ 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
@@ -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.\r
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(:open).with("file_name","r") { StringIO.new(data) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subtitle_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twin Panichsombat