moving_words 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ae83eed33f0e46c66cc67e607733aacc0fd6a21
4
- data.tar.gz: 5996bafe18776a506dbbcf5e82c1e520a2a57f35
3
+ metadata.gz: 646ed7d8017ca3b438ce1daf0d35a9239a5689ee
4
+ data.tar.gz: aa0f60a76a77dfce5e2a52f875ad89988e94690d
5
5
  SHA512:
6
- metadata.gz: e96fefcb675625551efc777ef195ee6634a83b78829ca9fe2f554fa768ba6f677bfed00b026d146b367bea974a08accc1577d6b8dc89e4d31eafa00ac5e99323
7
- data.tar.gz: 8f349a29b02215627fad49c6e3036c29592a432a8fc8667830c3138b86d7416ff959e9495a2d88ff5cd979a6d134f56d8ab2d315396594e8fd8cb1bd0ac149db
6
+ metadata.gz: d17d2f99adbd873bde04491bda6ae8c10768fc77825128ae68790f83c3bcb80ce4b1c5162e4867766864e82d42a1afce537fe112bae9b9659da3d4632d07b77e
7
+ data.tar.gz: 517d77254de3d08e0f1c51ede0d9e03d7d0e2a952722e17bad53efc4b325eee96be7f7ab5ebf616c83a6c699bbf167723e85527f4300377e373835ac87f3904b
data/CHANGELOG ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.0.2 - 2014-02-10
4
+
5
+ * Added `CaptionBlock.human_offset` method for outputting human readable offsets.
6
+
7
+ ## 0.0.1 - 2014-02-09
8
+
9
+ * Initial release.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module MovingWords
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Caption
3
+ module MovingWords
4
4
  describe SrtParser do
5
5
  describe "#parse" do
6
6
  let(:parser) { SrtParser.new <<EOF
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.1
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: