bamnet-acts-as-timecode 1.0.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.
- data/MIT-LICENSE +20 -0
- data/README +25 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/acts-as-timecode.gemspec +43 -0
- data/init.rb +2 -0
- data/lib/acts_as_timecode.rb +56 -0
- data/test/acts_as_timecode_test.rb +83 -0
- metadata +60 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Brian Michalski [[http://www.brispace.net]]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
ActsAsTimecode
|
2
|
+
==============
|
3
|
+
|
4
|
+
A simple plugin to transform a field stored as seconds into a timecode in the format of HH:MM:SS.
|
5
|
+
|
6
|
+
The timecode can be set in any of the following formats:
|
7
|
+
HH:MM:SS:FF
|
8
|
+
HH:MM:SS
|
9
|
+
MM:SS
|
10
|
+
SS
|
11
|
+
|
12
|
+
Frames will be converted to seconds and rounded, based on the :fps value (default fps = 30)
|
13
|
+
|
14
|
+
Example
|
15
|
+
=======
|
16
|
+
|
17
|
+
class Video < ActiveRecord::Base
|
18
|
+
acts_as_timecode :column => :duration
|
19
|
+
end
|
20
|
+
|
21
|
+
video.timecode = "01:23:45"
|
22
|
+
video.duration = 5025
|
23
|
+
|
24
|
+
|
25
|
+
Copyright (c) 2009 Brian Michalski, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the acts_as_timecode plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the acts_as_timecode plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'ActsAsTimecode'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'jeweler'
|
27
|
+
Jeweler::Tasks.new do |gemspec|
|
28
|
+
gemspec.name = "acts-as-timecode"
|
29
|
+
gemspec.summary = "ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF"
|
30
|
+
gemspec.email = "bmichalski@gmail.com"
|
31
|
+
gemspec.homepage = "http://www.brispace.net"
|
32
|
+
gemspec.description = "ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF"
|
33
|
+
gemspec.authors = ["Brian Michalski"]
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{acts-as-timecode}
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brian Michalski"]
|
9
|
+
s.date = %q{2009-06-03}
|
10
|
+
s.description = %q{ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF}
|
11
|
+
s.email = %q{bmichalski@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
"MIT-LICENSE",
|
17
|
+
"README",
|
18
|
+
"Rakefile",
|
19
|
+
"VERSION",
|
20
|
+
"acts-as-timecode.gemspec",
|
21
|
+
"init.rb",
|
22
|
+
"lib/acts_as_timecode.rb",
|
23
|
+
"test/acts_as_timecode_test.rb"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://www.brispace.net}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.4}
|
29
|
+
s.summary = %q{ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF}
|
30
|
+
s.test_files = [
|
31
|
+
"test/acts_as_timecode_test.rb"
|
32
|
+
]
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
39
|
+
else
|
40
|
+
end
|
41
|
+
else
|
42
|
+
end
|
43
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# ActsAsTimecode
|
2
|
+
module Acts
|
3
|
+
module Timecode
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def acts_as_timecode(options = {})
|
10
|
+
configuration = {:column => "length", :fps => 30}
|
11
|
+
configuration.update(options) if options.is_a?(Hash)
|
12
|
+
class_eval <<-EOV
|
13
|
+
|
14
|
+
include Acts::Timecode::InstanceMethods
|
15
|
+
def timecode_column
|
16
|
+
'#{configuration[:column]}'
|
17
|
+
end
|
18
|
+
def fps
|
19
|
+
@fps = '#{configuration[:fps]}'.to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
EOV
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
def timecode
|
28
|
+
hours = send(timecode_column).to_i/(60*60).to_i
|
29
|
+
rem = send(timecode_column).to_i - hours * (60*60)
|
30
|
+
minutes = rem/(60).to_i
|
31
|
+
rem = rem - minutes * (60)
|
32
|
+
seconds = rem
|
33
|
+
@timecode = "#{hours.to_s.rjust(2,'0')}:#{minutes.to_s.rjust(2,'0')}:#{seconds.to_s.rjust(2,'0')}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def timecode=(value)
|
37
|
+
matches = value.split(':')
|
38
|
+
matches.map!{|s| s.to_i}
|
39
|
+
case matches.length
|
40
|
+
#HH:MM:SS:FF
|
41
|
+
when 4
|
42
|
+
write_attribute(timecode_column, ((matches[0]*60*60) + (matches[1] * 60) + matches[2] + matches[3]/fps).round)
|
43
|
+
#HH:MM:SS
|
44
|
+
when 3
|
45
|
+
write_attribute(timecode_column, (matches[0]*60*60) + (matches[1] * 60) + matches[2])
|
46
|
+
#MM:SS
|
47
|
+
when 2
|
48
|
+
write_attribute(timecode_column, matches[0] * (60) + matches[1])
|
49
|
+
#SS
|
50
|
+
else
|
51
|
+
write_attribute(timecode_column, value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
require "#{File.dirname(__FILE__)}/../init"
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
8
|
+
|
9
|
+
def setup_db
|
10
|
+
ActiveRecord::Schema.define(:version => 1) do
|
11
|
+
create_table :vids do |t|
|
12
|
+
t.column :desired, :string
|
13
|
+
t.column :duration, :integer
|
14
|
+
t.column :created_at, :datetime
|
15
|
+
t.column :updated_at, :datetime
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown_db
|
21
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
22
|
+
ActiveRecord::Base.connection.drop_table(table)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Vid < ActiveRecord::Base
|
27
|
+
end
|
28
|
+
|
29
|
+
class TimecodeVid < Vid
|
30
|
+
acts_as_timecode :column => :duration
|
31
|
+
|
32
|
+
def self.table_name() "vids" end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ActsAsTimecodeTest < Test::Unit::TestCase
|
36
|
+
|
37
|
+
def setup
|
38
|
+
setup_db
|
39
|
+
TimecodeVid.create! :desired => "00:00:00", :duration => 0
|
40
|
+
TimecodeVid.create! :desired => "00:01:00", :duration => 60
|
41
|
+
TimecodeVid.create! :desired => "00:01:33", :duration => 93
|
42
|
+
TimecodeVid.create! :desired => "25:12:59", :duration => 90779
|
43
|
+
end
|
44
|
+
def teardown
|
45
|
+
teardown_db
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_getting
|
49
|
+
assert_equal TimecodeVid.find(1).desired, TimecodeVid.find(1).timecode
|
50
|
+
assert_equal TimecodeVid.find(2).desired, TimecodeVid.find(2).timecode
|
51
|
+
assert_equal TimecodeVid.find(3).desired, TimecodeVid.find(3).timecode
|
52
|
+
assert_equal TimecodeVid.find(4).desired, TimecodeVid.find(4).timecode
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_setting
|
56
|
+
@T2 = TimecodeVid.find(2)
|
57
|
+
@T2.timecode = "00:00:00"
|
58
|
+
|
59
|
+
assert_not_equal @T2.desired, @T2.duration
|
60
|
+
assert_equal @T2.timecode, TimecodeVid.find(1).desired
|
61
|
+
|
62
|
+
@T3 = TimecodeVid.find(3)
|
63
|
+
@T3.timecode = "00:60:60"
|
64
|
+
@T3.save
|
65
|
+
|
66
|
+
assert_equal @T3.timecode, "01:01:00"
|
67
|
+
assert_equal @T3.duration, 3660
|
68
|
+
|
69
|
+
@T3.timecode = "01:05:15:24"
|
70
|
+
#The real value here is 3915.8, but we are working in seconds so we round
|
71
|
+
assert_equal @T3.duration, 3916
|
72
|
+
|
73
|
+
@T3.timecode = "59:01"
|
74
|
+
assert_equal @T3.timecode, "00:59:01"
|
75
|
+
assert_equal @T3.duration, 3541
|
76
|
+
|
77
|
+
@T3.timecode = "32"
|
78
|
+
assert_equal @T3.timecode, "00:00:32"
|
79
|
+
assert_equal @T3.duration, 32
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bamnet-acts-as-timecode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Michalski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF
|
17
|
+
email: bmichalski@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README
|
27
|
+
- Rakefile
|
28
|
+
- VERSION
|
29
|
+
- acts-as-timecode.gemspec
|
30
|
+
- init.rb
|
31
|
+
- lib/acts_as_timecode.rb
|
32
|
+
- test/acts_as_timecode_test.rb
|
33
|
+
has_rdoc: false
|
34
|
+
homepage: http://www.brispace.net
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: ActsAsTimecode provides a timecode field, converting a duration to HH:MM:SS:FF
|
59
|
+
test_files:
|
60
|
+
- test/acts_as_timecode_test.rb
|