srt 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ script:
2
+ - bundle exec rake spec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SRT
1
+ # SRT [![Build Status](https://travis-ci.org/cpetersen/srt.png?branch=master)](https://travis-ci.org/cpetersen/srt)
2
2
 
3
3
  SRT stands for SubRip text file format, which is a file for storing subtitles. This is a Ruby library for manipulating SRT files.
4
4
 
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 Srt
2
- VERSION = "0.0.1"
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 = SRT::Line.new(:text => "This is a test")
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. This is a Ruby library for manipulating SRT files.}
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 = Srt::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.1
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-21 00:00:00.000000000 Z
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: SRT stands for SubRip text file format, which is a file for storing subtitles.
47
- This is a Ruby library for manipulating SRT files.
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: -3640544855343307444
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: -3640544855343307444
90
+ hash: -853641562359327815
90
91
  requirements: []
91
92
  rubyforge_project:
92
93
  rubygems_version: 1.8.24