srtshifter 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,4 +63,4 @@ module SrtShifter
63
63
  end
64
64
  end
65
65
  end
66
- end
66
+ end
@@ -38,15 +38,26 @@ module SrtShifter
38
38
  puts "Elapsed time: #{end_time-start_time} seconds."
39
39
  end
40
40
 
41
- def convert_time time
42
-
43
- if @opts[:operation] == "SUB" and @opts[:time] > 0
44
- @opts[:time] = -@opts[:time]
45
- end
46
-
47
- current_time = Time.parse(time)
48
- new_time = Time.at(current_time.to_f + @opts[:time])
49
- "#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
50
- end
51
- end
41
+ def convert_time(time)
42
+ time_diff = time_in_seconds(@opts[:time])
43
+ if @opts[:operation] == "SUB" and time_diff > 0
44
+ time_diff *= -1
45
+ end
46
+
47
+ current_time = Time.parse(time)
48
+ new_time = Time.at(current_time.to_f + time_diff)
49
+ "#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
50
+ end
51
+
52
+ private
53
+
54
+ def time_in_seconds(time_string)
55
+ return time_string if time_string.kind_of?(Numeric)
56
+
57
+ times = time_string.scan(/(\d{2}):(\d{2}):(\d{2}).(\d{3})/)
58
+ times.flatten!
59
+ times.map!(&:to_i)
60
+ times[3]/1_000.0 + times[2] + 60*(times[1] + times[0]*60)
61
+ end
62
+ end
52
63
  end
@@ -1,3 +1,3 @@
1
1
  module SrtShifter
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/srtshifter.gemspec CHANGED
@@ -19,5 +19,4 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
20
  gem.require_paths = ["lib"]
21
21
  gem.add_development_dependency 'rake'
22
- gem.add_development_dependency 'coveralls'
23
22
  end
@@ -53,4 +53,4 @@ describe SrtShifter do
53
53
 
54
54
  end
55
55
 
56
- end
56
+ end
@@ -38,6 +38,33 @@ describe SrtShifter do
38
38
 
39
39
  end
40
40
 
41
+ it "must accept time in '%H:%M:%S.%L' format in ADD operation" do
42
+ given_time = "00:00:10,000"
43
+ @options[:operation] = "ADD"
44
+ @options[:time] = "01:20:03.999"
45
+
46
+ sub = SrtShifter::Subtitle.new(@options)
47
+ sub.convert_time(given_time).must_equal "01:20:13,999"
48
+ end
49
+
50
+ it "must accept time in '%H:%M:%S.%L' format in SUB operation" do
51
+ given_time = "01:20:03,999"
52
+ @options[:operation] = "SUB"
53
+ @options[:time] = "01:20:01.999"
54
+
55
+ sub = SrtShifter::Subtitle.new(@options)
56
+ sub.convert_time(given_time).must_equal "00:00:02,000"
57
+ end
58
+
59
+ it "must accept time in '-%H:%M:%S.%L' format in SUB operation" do
60
+ given_time = "01:20:03,999"
61
+ @options[:operation] = "SUB"
62
+ @options[:time] = "-01:20:01.999"
63
+
64
+ sub = SrtShifter::Subtitle.new(@options)
65
+ sub.convert_time(given_time).must_equal "00:00:02,000"
66
+ end
67
+
41
68
  end
42
69
 
43
70
  describe "shift" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srtshifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: coveralls
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
30
  description: Shifts STR Subtitles
47
31
  email:
48
32
  - kimobr@gmail.com