subber 0.1.4 → 0.1.8

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: 9c082a74b89529051c409e05338515568c17dc26
4
- data.tar.gz: aa6dc20d6082c75894abb08261e55baca483e708
3
+ metadata.gz: 0d99774cbda4336ea215569220767f66527e1934
4
+ data.tar.gz: 86c850d34a871e2c97b31cad63605ff4533cdf36
5
5
  SHA512:
6
- metadata.gz: e83d6e85c03d1cc6f4e9fa3e980d034361495d05134f93a48836ead18b882b55e9e225800fdde5745b7f446871f6d2ef6774100a0badf5fb30d41ec0ed444f3b
7
- data.tar.gz: 7c3d78acb225b3d14ec74c487c1a0e150a73e7f799a8cfa08c48d40770dee57142d05d8af39d936ba590c8e029d2c91118250b71dd2273661c3cc0846a70e26f
6
+ metadata.gz: a749c05830ea797c0484f96217bdc7fb4a0415005ff5806941f8b5bce9e82f3452474847f31c5ecc88a9d082df3f2e1560790df025d8958844961704059f29e4
7
+ data.tar.gz: a524ce7dc665f0ec04b10378b7ffc4c79a0a6eaf33fec5a8f7ef011998eb2918d0029cd1d7144502edc2fc8da17590e73dacf5961a83203e35b7c4f118d0566f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- subber (0.1.4)
4
+ subber (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -56,6 +56,21 @@ module Subber::File
56
56
  File.write(path, content)
57
57
  end
58
58
 
59
+ # @param ms [Integer] Can be both positive and negative
60
+ # @return [Subber::File::Base] return a new copy with shifted subtitles
61
+ #
62
+ def shift(ms)
63
+ new_subtitles = subtitles.map { |subtitle| subtitle.shift(ms) }
64
+ self.class.new(subtitles: new_subtitles)
65
+ end
66
+
67
+ # @param ms [Integer] Can be both positive and negative
68
+ # mutates the current file's subtitles
69
+ #
70
+ def shift!(ms)
71
+ subtitles.each { |subtitle| subtitle.shift!(ms) }
72
+ end
73
+
59
74
  private
60
75
 
61
76
  def formatter
@@ -1,13 +1,12 @@
1
1
  module Subber::Parser
2
2
  class Srt < Base
3
3
  SUBTITLE_REGEX = /([^\n]*)\n([^\n]*)(\n(.*))?/m
4
- COUNTER_REGEX = /\d+/
4
+ COUNTER_REGEX = /(\d+)$/
5
5
  TIME_RANGE_REGEX = /(\d{2}:\d{2}:\d{2},\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2},\d{3})/
6
6
  TIMECODE_REGEX = /(\d{2}):(\d{2}):(\d{2}),(\d{3})/
7
7
 
8
8
  DELIMITER_REGEX = /\n?\n\n/
9
9
  WINDOW_LINE_BREAK_REGEX = /\r/
10
- BYTE_ORDER_MARK_STRING = "\xEF\xBB\xBF"
11
10
 
12
11
  class << self
13
12
  # @param file_content [String]
@@ -62,9 +61,9 @@ module Subber::Parser
62
61
  # @raise [Subber::Errors::InvalidCounter]
63
62
  #
64
63
  def extract_counter(text)
65
- raise(Subber::Errors::InvalidCounter) if text.match(COUNTER_REGEX).nil?
66
- text.sub!(BYTE_ORDER_MARK_STRING, '')
67
- text.to_i
64
+ counter_text = text.match(COUNTER_REGEX).to_a.last
65
+ raise(Subber::Errors::InvalidCounter) if counter_text.nil?
66
+ counter_text.to_i
68
67
  end
69
68
 
70
69
  # @param text [String]
@@ -10,4 +10,33 @@ class Subber::Subtitle
10
10
  @end_time = attributes[:end_time]
11
11
  @content = attributes[:content]
12
12
  end
13
+
14
+ def as_json
15
+ {
16
+ 'counter' => counter,
17
+ 'start_time' => start_time,
18
+ 'end_time' => end_time,
19
+ 'content' => content
20
+ }
21
+ end
22
+
23
+ # @param miliseconds [Integer] Can be both positive and negative
24
+ # @return [Subber::Subtitle] return a copy with shifted subtitle
25
+ #
26
+ def shift(ms)
27
+ self.class.new(
28
+ counter: counter,
29
+ start_time: start_time + ms,
30
+ end_time: end_time + ms,
31
+ content: content
32
+ )
33
+ end
34
+
35
+ # @param miliseconds [Integer] Can be both positive and negative
36
+ # mutates the current subtitle's start and end time by ms
37
+ #
38
+ def shift!(ms)
39
+ @start_time += ms
40
+ @end_time += ms
41
+ end
13
42
  end
@@ -1,3 +1,3 @@
1
1
  module Subber
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.4.5.2
121
+ rubygems_version: 2.5.2
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Subtitle converter