srt 0.0.1 → 0.0.2
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.
- data/.travis.yml +2 -0
- data/README.md +1 -1
- data/lib/srt/file.rb +11 -0
- data/lib/srt/line.rb +6 -0
- data/lib/srt/version.rb +2 -2
- data/spec/srt_spec.rb +33 -2
- data/srt.gemspec +3 -3
- metadata +8 -7
data/.travis.yml
ADDED
data/README.md
CHANGED
data/lib/srt/file.rb
CHANGED
@@ -36,6 +36,17 @@ module SRT
|
|
36
36
|
result
|
37
37
|
end
|
38
38
|
|
39
|
+
def to_s
|
40
|
+
result = []
|
41
|
+
lines.each do |line|
|
42
|
+
result << line.sequence
|
43
|
+
result << line.time_str
|
44
|
+
result += line.text
|
45
|
+
result << ""
|
46
|
+
end
|
47
|
+
result.join("\n")
|
48
|
+
end
|
49
|
+
|
39
50
|
attr_writer :lines
|
40
51
|
def lines
|
41
52
|
@lines ||= []
|
data/lib/srt/line.rb
CHANGED
@@ -18,5 +18,11 @@ module SRT
|
|
18
18
|
def empty?
|
19
19
|
sequence.nil? && start_time.nil? && end_time.nil? && text.empty?
|
20
20
|
end
|
21
|
+
|
22
|
+
def time_str
|
23
|
+
s = start_time ? start_time.strftime("%H:%M:%S,%L") : ""
|
24
|
+
e = end_time ? end_time.strftime("%H:%M:%S,%L") : ""
|
25
|
+
"#{s} --> #{e}"
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
data/lib/srt/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module SRT
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/spec/srt_spec.rb
CHANGED
@@ -2,16 +2,21 @@ require 'srt'
|
|
2
2
|
|
3
3
|
describe SRT do
|
4
4
|
context "A single line" do
|
5
|
+
let(:line) { SRT::Line.new }
|
5
6
|
it "should be empty" do
|
6
|
-
line = SRT::Line.new
|
7
7
|
line.should be_empty
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should not be empty" do
|
11
|
-
line
|
11
|
+
line.text = "This is a test"
|
12
12
|
line.should_not be_empty
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should have the correct time string" do
|
16
|
+
line.start_time = DateTime.strptime("00:00:02,110", "%H:%M:%S,%L")
|
17
|
+
line.end_time = DateTime.strptime("00:00:04,578", "%H:%M:%S,%L")
|
18
|
+
line.time_str.should == "00:00:02,110 --> 00:00:04,578"
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
context "A properly formatted SRT file" do
|
@@ -69,4 +74,30 @@ describe SRT do
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
77
|
+
context "A short SRT file" do
|
78
|
+
let(:file) {
|
79
|
+
file = SRT::File.parse(File.open("./spec/bsg-s01e01.srt"))
|
80
|
+
file.lines = file.lines[0..2]
|
81
|
+
file
|
82
|
+
}
|
83
|
+
|
84
|
+
it "should have the proper to_s" do
|
85
|
+
OUTPUT =<<END
|
86
|
+
1
|
87
|
+
00:00:02,110 --> 00:00:04,578
|
88
|
+
<i>(male narrator) Previously
|
89
|
+
on Battlestar Galactica.</i>
|
90
|
+
|
91
|
+
2
|
92
|
+
00:00:05,313 --> 00:00:06,871
|
93
|
+
Now you're telling me
|
94
|
+
you're a machine.
|
95
|
+
|
96
|
+
3
|
97
|
+
00:00:07,014 --> 00:00:08,003
|
98
|
+
The robot.
|
99
|
+
END
|
100
|
+
file.to_s.should == OUTPUT
|
101
|
+
end
|
102
|
+
end
|
72
103
|
end
|
data/srt.gemspec
CHANGED
@@ -4,9 +4,9 @@ require File.expand_path('../lib/srt/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Christopher Petersen"]
|
6
6
|
gem.email = ["christopher.petersen@gmail.com"]
|
7
|
-
gem.description = %q{SRT stands for SubRip text file format, which is a file for storing subtitles.
|
7
|
+
gem.description = %q{Ruby gem for parsing srt (subtitle) files. SRT stands for SubRip text file format, which is a file for storing subtitles.}
|
8
8
|
gem.summary = %q{Ruby gem for parsing subtitle files.}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/cpetersen/srt"
|
10
10
|
|
11
11
|
gem.add_development_dependency('rake')
|
12
12
|
gem.add_development_dependency('rspec')
|
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.name = "srt"
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
gem.version =
|
19
|
+
gem.version = SRT::VERSION
|
20
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srt
|
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,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description:
|
47
|
-
|
46
|
+
description: Ruby gem for parsing srt (subtitle) files. SRT stands for SubRip text
|
47
|
+
file format, which is a file for storing subtitles.
|
48
48
|
email:
|
49
49
|
- christopher.petersen@gmail.com
|
50
50
|
executables: []
|
@@ -52,6 +52,7 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
55
56
|
- Gemfile
|
56
57
|
- LICENSE
|
57
58
|
- README.md
|
@@ -63,7 +64,7 @@ files:
|
|
63
64
|
- spec/bsg-s01e01.srt
|
64
65
|
- spec/srt_spec.rb
|
65
66
|
- srt.gemspec
|
66
|
-
homepage:
|
67
|
+
homepage: https://github.com/cpetersen/srt
|
67
68
|
licenses: []
|
68
69
|
post_install_message:
|
69
70
|
rdoc_options: []
|
@@ -77,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
segments:
|
79
80
|
- 0
|
80
|
-
hash: -
|
81
|
+
hash: -853641562359327815
|
81
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
83
|
none: false
|
83
84
|
requirements:
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
version: '0'
|
87
88
|
segments:
|
88
89
|
- 0
|
89
|
-
hash: -
|
90
|
+
hash: -853641562359327815
|
90
91
|
requirements: []
|
91
92
|
rubyforge_project:
|
92
93
|
rubygems_version: 1.8.24
|