voot 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f0b1b7d1b82d3b452c84daabe479a407bd86e14
4
+ data.tar.gz: c89d119e5d1365d2943e597311c567b44f063f82
5
+ SHA512:
6
+ metadata.gz: e784362950fbe7b40259284438202fffbb250297340e71ebd07ec978dc78f13ee5b22f74c6d4321dc3b398b6f764da59e8fe5b770f203231d70e4f930a5b8f71
7
+ data.tar.gz: 4e19b0731cb1d9507d6d3e322fdd07c7737ea6a099f71341a5e2e024563f6b0e9854ffa42f8ab60d8ab4e573e994a2f541c3ff853de856497fbce77bf2ef426a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ voot
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p195
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 1.9.2
4
+ - 2.0.0
5
+ script: script/ci.sh
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in voot.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ guard 'bundler' do
4
+ watch('Gemfile')
5
+ watch(/^.+\.gemspec/)
6
+ end
7
+
8
+ guard :rspec do
9
+ watch(%r{^spec/.+_spec\.rb$})
10
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
11
+ watch('spec/spec_helper.rb') { "spec" }
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Doc Ritezel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Voot
2
+
3
+ [![Build Status](https://travis-ci.org/minifast/voot.png)](https://travis-ci.org/minifast/voot) [![Code Climate](https://codeclimate.com/github/minifast/voot.png)](https://codeclimate.com/github/minifast/voot)
4
+
5
+ Voot lets you read and write WebVTT files with great ease.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'voot'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install voot
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/voot.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "voot/version"
2
+ require "voot/vtt"
3
+
4
+ module Voot
5
+ end
data/lib/voot/cue.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "voot/cue_timing"
2
+
3
+ module Voot
4
+ class Cue
5
+ attr_reader :identifier, :cue_timing, :payload
6
+
7
+ def initialize(options = {})
8
+ @identifier = options[:identifier]
9
+ @cue_timing = options.fetch(:cue_timing)
10
+ @payload = options.fetch(:payload)
11
+ end
12
+
13
+ def has_identifier?
14
+ !identifier.nil? && identifier.length > 0
15
+ end
16
+
17
+ def to_webvtt
18
+ if has_identifier?
19
+ "#{identifier}\n#{cue_timing.to_webvtt}\n#{payload}"
20
+ else
21
+ "#{cue_timing.to_webvtt}\n#{payload}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ require "voot/cue"
2
+
3
+ module Voot
4
+ class CueList < Array
5
+
6
+ def to_webvtt
7
+ map(&:to_webvtt).join("\n\n")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module Voot
2
+ class CueTiming
3
+ attr_reader :start_seconds, :end_seconds
4
+
5
+ def initialize(options = {})
6
+ @start_seconds = options.fetch(:start_seconds)
7
+ @end_seconds = options.fetch(:end_seconds)
8
+ end
9
+
10
+ def to_webvtt
11
+ "#{format_timestamp(start_seconds)} --> #{format_timestamp(end_seconds)}"
12
+ end
13
+
14
+ private
15
+
16
+ def format_timestamp(seconds)
17
+ "#{format_minutes(seconds)}:#{format_seconds(seconds)}.#{format_subseconds(seconds)}"
18
+ end
19
+
20
+ def format_minutes(seconds)
21
+ (seconds.to_i / 60).to_s.rjust(2, "0")
22
+ end
23
+
24
+ def format_seconds(seconds)
25
+ (seconds.to_i % 60).to_s.rjust(2, "0")
26
+ end
27
+
28
+ def format_subseconds(seconds)
29
+ ((seconds * 1000).round % 1000).to_s.rjust(3, "0")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Voot
2
+ VERSION = "0.1.0"
3
+ end
data/lib/voot/vtt.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "voot/cue_list"
2
+
3
+ module Voot
4
+ class Vtt
5
+ attr_reader :path
6
+ attr_accessor :header
7
+
8
+ def initialize(options = {})
9
+ @path = options.fetch(:path)
10
+ @header = options[:header]
11
+ end
12
+
13
+ def cues
14
+ @cues ||= Voot::CueList.new
15
+ end
16
+
17
+ def to_webvtt
18
+ if has_header?
19
+ "WEBVTT #{header}\n\n#{cues.to_webvtt}"
20
+ else
21
+ "WEBVTT\n\n#{cues.to_webvtt}"
22
+ end
23
+ end
24
+
25
+ def has_header?
26
+ !header.nil? && header.length > 0
27
+ end
28
+
29
+ def save
30
+ ensure_destination_directory
31
+ File.open(path, "w") { |destination| destination.write(to_webvtt) }
32
+ end
33
+
34
+ private
35
+
36
+ def ensure_destination_directory
37
+ FileUtils.mkdir_p(File.dirname(path))
38
+ end
39
+ end
40
+ end
data/script/ci.sh ADDED
@@ -0,0 +1 @@
1
+ bundle exec rspec
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Voot::CueList do
4
+ subject(:cue_list) { Voot::CueList.new }
5
+
6
+ describe "#to_webvtt" do
7
+ context "when the list is empty" do
8
+ its(:to_webvtt) { should be_empty }
9
+ end
10
+
11
+ context "when the list has an item in it" do
12
+ before { cue_list << create_cue("reasonably priced", 0, 0) }
13
+
14
+ its(:to_webvtt) { should == "00:00.000 --> 00:00.000\nreasonably priced" }
15
+
16
+ context "when the list has multiple items" do
17
+ before { cue_list << create_cue("toiletries", 1, 1) }
18
+
19
+ its(:to_webvtt) { should include "00:01.000 --> 00:01.000\ntoiletries" }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Voot::Cue do
4
+ let(:identifier) { "taco massacre" }
5
+ let(:payload) { "tasty" }
6
+ let(:cue_timing) { Voot::CueTiming.new(start_seconds: 0, end_seconds: 1) }
7
+
8
+ subject(:cue) do
9
+ Voot::Cue.new(
10
+ identifier: identifier,
11
+ cue_timing: cue_timing,
12
+ payload: payload
13
+ )
14
+ end
15
+
16
+ describe "#has_identifier?" do
17
+ context "when the identifier is set" do
18
+ it { should have_identifier }
19
+ end
20
+
21
+ context "when the identifier is nil" do
22
+ let(:identifier) { nil }
23
+
24
+ it { should_not have_identifier }
25
+ end
26
+
27
+ context "when the identifier is an empty string" do
28
+ let(:identifier) { "" }
29
+
30
+ it { should_not have_identifier }
31
+ end
32
+ end
33
+
34
+ describe "#to_webvtt" do
35
+ context "when the identifier is set" do
36
+ its(:to_webvtt) { should == "taco massacre\n00:00.000 --> 00:01.000\ntasty" }
37
+ end
38
+
39
+ context "when the identifier is not set" do
40
+ let(:identifier) { nil }
41
+
42
+ its(:to_webvtt) { should == "00:00.000 --> 00:01.000\ntasty" }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe Voot::CueTiming do
4
+ let(:start_seconds) { 1.0001 }
5
+ let(:end_seconds) { 65.0009 }
6
+
7
+ subject(:cue_timing) do
8
+ Voot::CueTiming.new(
9
+ start_seconds: start_seconds,
10
+ end_seconds: end_seconds
11
+ )
12
+ end
13
+
14
+ its(:to_webvtt) { should == "00:01.000 --> 01:05.001" }
15
+ end
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+
3
+ describe Voot::Vtt do
4
+ let(:vtt_path) { Tempfile.new("voot-file").path }
5
+
6
+ subject(:vtt) { Voot::Vtt.new(path: vtt_path) }
7
+
8
+ describe "#save" do
9
+ context "when the file does not exist" do
10
+ before { FileUtils.rm(vtt_path) }
11
+
12
+ it "creates the file" do
13
+ expect do
14
+ vtt.save
15
+ end.to change { File.exist?(vtt_path) }.to(true)
16
+ end
17
+ end
18
+
19
+ context "when the file exists" do
20
+ let(:pesky_user_data) { "hey guys tacos are great right" }
21
+
22
+ before { File.write(vtt_path, pesky_user_data) }
23
+
24
+ it "clobbers the file content" do
25
+ expect do
26
+ vtt.save
27
+ end.to change { File.read(vtt_path) }.from(pesky_user_data)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#has_header?" do
33
+ before { vtt.header = header }
34
+
35
+ context "when the header is an empty string" do
36
+ let(:header) { "" }
37
+
38
+ it { should_not have_header }
39
+ end
40
+
41
+ context "when the header is nil" do
42
+ let(:header) { nil }
43
+
44
+ it { should_not have_header }
45
+ end
46
+
47
+ context "when the header not empty or nil" do
48
+ let(:header) { "geese on parade" }
49
+
50
+ it { should have_header }
51
+ end
52
+ end
53
+
54
+ describe "#to_webvtt" do
55
+ context "when the header is empty" do
56
+ its(:to_webvtt) { should == "WEBVTT\n\n" }
57
+ end
58
+
59
+ context "when the header has content" do
60
+ before { vtt.header = "here is a video of abbey the cat" }
61
+
62
+ its(:to_webvtt) { should == "WEBVTT here is a video of abbey the cat\n\n" }
63
+ end
64
+
65
+ context "when there is a cue" do
66
+ before { vtt.cues << create_cue("not the drill!", 0, 2) }
67
+
68
+ its(:to_webvtt) { should == "WEBVTT\n\n00:00.000 --> 00:02.000\nnot the drill!" }
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,14 @@
1
+ $:<< File.expand_path("../../lib", __FILE__)
2
+
3
+ require "voot"
4
+
5
+ Dir.glob(File.expand_path("../support/**/*.rb", __FILE__)) { |f| require f }
6
+
7
+ RSpec.configure do |config|
8
+ config.include CueHelper
9
+
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ config.order = 'random'
14
+ end
@@ -0,0 +1,6 @@
1
+ module CueHelper
2
+ def create_cue(payload, start, stop)
3
+ cue_timing = Voot::CueTiming.new(start_seconds: start, end_seconds: stop)
4
+ Voot::Cue.new(cue_timing: cue_timing, payload: payload)
5
+ end
6
+ end
data/voot.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'voot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "voot"
8
+ spec.version = Voot::VERSION
9
+ spec.authors = ["Doc Ritezel"]
10
+ spec.email = ["doc@minifast.co"]
11
+ spec.description = %q{WebVTT generation, parsing and manipulation}
12
+ spec.summary = %q{Easily create, read and write WebVTT files}
13
+ spec.homepage = "https://github.com/minifast/voot"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.executables = `git ls-files -- bin`.split("\n").map { |f| File.basename(f) }
18
+ spec.test_files = `git ls-files -- spec`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "guard-rspec"
23
+ spec.add_development_dependency "guard-bundler"
24
+ spec.add_development_dependency "gem-release"
25
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doc Ritezel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem-release
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: WebVTT generation, parsing and manipulation
70
+ email:
71
+ - doc@minifast.co
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .ruby-gemset
79
+ - .ruby-version
80
+ - .travis.yml
81
+ - Gemfile
82
+ - Guardfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - lib/voot.rb
87
+ - lib/voot/cue.rb
88
+ - lib/voot/cue_list.rb
89
+ - lib/voot/cue_timing.rb
90
+ - lib/voot/version.rb
91
+ - lib/voot/vtt.rb
92
+ - script/ci.sh
93
+ - spec/lib/voot/cue_list_spec.rb
94
+ - spec/lib/voot/cue_spec.rb
95
+ - spec/lib/voot/cue_timing_spec.rb
96
+ - spec/lib/voot/vtt_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/support/cue_helper.rb
99
+ - voot.gemspec
100
+ homepage: https://github.com/minifast/voot
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.0.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Easily create, read and write WebVTT files
124
+ test_files:
125
+ - spec/lib/voot/cue_list_spec.rb
126
+ - spec/lib/voot/cue_spec.rb
127
+ - spec/lib/voot/cue_timing_spec.rb
128
+ - spec/lib/voot/vtt_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/cue_helper.rb