moving_words 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.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/lib/moving_words/caption_block.rb +41 -0
- data/lib/moving_words/version.rb +1 -1
- data/spec/caption_block_spec.rb +19 -0
- data/spec/srt_parser_spec.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 646ed7d8017ca3b438ce1daf0d35a9239a5689ee
|
4
|
+
data.tar.gz: aa0f60a76a77dfce5e2a52f875ad89988e94690d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d17d2f99adbd873bde04491bda6ae8c10768fc77825128ae68790f83c3bcb80ce4b1c5162e4867766864e82d42a1afce537fe112bae9b9659da3d4632d07b77e
|
7
|
+
data.tar.gz: 517d77254de3d08e0f1c51ede0d9e03d7d0e2a952722e17bad53efc4b325eee96be7f7ab5ebf616c83a6c699bbf167723e85527f4300377e373835ac87f3904b
|
data/CHANGELOG
ADDED
@@ -16,5 +16,46 @@ module MovingWords
|
|
16
16
|
self.end_time = end_time
|
17
17
|
self.content = content
|
18
18
|
end
|
19
|
+
|
20
|
+
# Public: Converts a millisecond offset to a more
|
21
|
+
# human-readable format of hh:mm:ss.
|
22
|
+
#
|
23
|
+
# offset_in_milliseconds - The millisecond offset to convert.
|
24
|
+
# options - Formatting options
|
25
|
+
# milliseconds: Includes milliseconds in the
|
26
|
+
# display output.
|
27
|
+
#
|
28
|
+
# Examples:
|
29
|
+
#
|
30
|
+
# CaptionBlock.human_offset(132212)
|
31
|
+
# => "2:12"
|
32
|
+
#
|
33
|
+
# CaptionBlock.human_offset(132212, milliseconds: true)
|
34
|
+
# => "2:12.212"
|
35
|
+
#
|
36
|
+
# CaptionBlock.human_offset(11075307)
|
37
|
+
# => "3:04:35"
|
38
|
+
def self.human_offset(offset_in_milliseconds, options = {})
|
39
|
+
hours = offset_in_milliseconds / 3600000
|
40
|
+
minutes = (offset_in_milliseconds % 360000) / 60000
|
41
|
+
seconds = (offset_in_milliseconds % 60000) / 1000
|
42
|
+
milliseconds = offset_in_milliseconds % 1000
|
43
|
+
|
44
|
+
time = ""
|
45
|
+
if hours > 0
|
46
|
+
time << "#{hours}:"
|
47
|
+
time << "%02d:" % minutes
|
48
|
+
else
|
49
|
+
time << "%1d:" % minutes
|
50
|
+
end
|
51
|
+
|
52
|
+
time << "%02d" % seconds
|
53
|
+
|
54
|
+
if options[:milliseconds]
|
55
|
+
time << ".%03d" % milliseconds
|
56
|
+
end
|
57
|
+
|
58
|
+
time
|
59
|
+
end
|
19
60
|
end
|
20
61
|
end
|
data/lib/moving_words/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MovingWords
|
4
|
+
describe CaptionBlock do
|
5
|
+
describe ".readable_offset" do
|
6
|
+
it "handles times with minutes without showing hours" do
|
7
|
+
expect(CaptionBlock.human_offset(132212)).to eq("2:12")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "shows milliseconds when requested" do
|
11
|
+
expect(CaptionBlock.human_offset(132212, milliseconds: true)).to eq("2:12.212")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "shows hours when they're needed" do
|
15
|
+
expect(CaptionBlock.human_offset(11075307)).to eq("3:04:35")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/srt_parser_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moving_words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Johnson
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- CHANGELOG
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/moving_words/srt_parser.rb
|
70
71
|
- lib/moving_words/version.rb
|
71
72
|
- moving_words.gemspec
|
73
|
+
- spec/caption_block_spec.rb
|
72
74
|
- spec/spec_helper.rb
|
73
75
|
- spec/srt_parser_spec.rb
|
74
76
|
homepage: https://github.com/commondream/moving_words
|
@@ -96,6 +98,7 @@ signing_key:
|
|
96
98
|
specification_version: 4
|
97
99
|
summary: Parse and work with captions. Supports SRT for now.
|
98
100
|
test_files:
|
101
|
+
- spec/caption_block_spec.rb
|
99
102
|
- spec/spec_helper.rb
|
100
103
|
- spec/srt_parser_spec.rb
|
101
104
|
has_rdoc:
|