ruby-duration 0.1.2 → 0.1.4
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/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/duration.rb +5 -6
- data/lib/duration/mongoid.rb +5 -5
- data/lib/ruby-duration.rb +1 -0
- data/ruby-duration.gemspec +60 -0
- data/test/duration/test_mongoid.rb +2 -1
- data/test/test_duration.rb +10 -0
- metadata +5 -4
data/Rakefile
CHANGED
@@ -30,7 +30,7 @@ begin
|
|
30
30
|
Rcov::RcovTask.new do |test|
|
31
31
|
test.libs << 'test'
|
32
32
|
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.rcov_opts << %w{--exclude /Library,.bundle,test}
|
33
|
+
test.rcov_opts << %w{--exclude /Library,.bundle,test,gems,.rvm}
|
34
34
|
test.verbose = true
|
35
35
|
end
|
36
36
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/duration.rb
CHANGED
@@ -8,13 +8,12 @@
|
|
8
8
|
# of themselves or perhaps provide a countdown until a certain event.
|
9
9
|
class Duration
|
10
10
|
include Comparable
|
11
|
-
include Enumerable
|
12
11
|
|
13
12
|
# Unit names
|
14
13
|
UNITS = [:seconds, :minutes, :hours, :days, :weeks]
|
15
14
|
|
16
15
|
# Unit labels
|
17
|
-
UNIT_LABELS = {:second => '
|
16
|
+
UNIT_LABELS = {:second => 'second',
|
18
17
|
:seconds => 'seconds',
|
19
18
|
:minute => 'minute',
|
20
19
|
:minutes => 'minutes',
|
@@ -38,8 +37,8 @@ class Duration
|
|
38
37
|
:week => 604800}
|
39
38
|
|
40
39
|
|
41
|
-
attr_reader :total,
|
42
|
-
|
40
|
+
attr_reader :total, :seconds, :minutes, :hours, :days, :weeks
|
41
|
+
|
43
42
|
# Initialize a duration. 'args' can be a hash or anything else. If a hash is
|
44
43
|
# passed, it will be scanned for a key=>value pair of time units such as those
|
45
44
|
# listed in the Duration::UNITS array or Duration::MULTIPLES hash.
|
@@ -53,7 +52,7 @@ class Duration
|
|
53
52
|
@seconds = 0
|
54
53
|
MULTIPLES.each do |unit, multiple|
|
55
54
|
unit = unit.to_sym
|
56
|
-
@seconds += args[unit] * multiple if args.key?(unit)
|
55
|
+
@seconds += args[unit].to_i * multiple if args.key?(unit)
|
57
56
|
end
|
58
57
|
else
|
59
58
|
@seconds = args.to_i
|
@@ -130,4 +129,4 @@ private
|
|
130
129
|
@weeks, @days, @hours, @minutes, @seconds = units
|
131
130
|
end
|
132
131
|
|
133
|
-
end
|
132
|
+
end
|
data/lib/duration/mongoid.rb
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
require 'duration'
|
3
3
|
|
4
4
|
class Duration
|
5
|
-
def get
|
6
|
-
|
5
|
+
def self.get(seconds)
|
6
|
+
Duration.new(seconds)
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.set(args)
|
10
10
|
if args.is_a?(Hash)
|
11
|
-
Duration.new(args)
|
11
|
+
Duration.new(args).to_i
|
12
12
|
elsif args.respond_to?(:to_i)
|
13
|
-
|
13
|
+
args.to_i
|
14
14
|
else
|
15
|
-
|
15
|
+
0
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/ruby-duration.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruby-duration}
|
8
|
+
s.version = "0.1.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jose Peleteiro"]
|
12
|
+
s.date = %q{2010-09-15}
|
13
|
+
s.description = %q{Duration type}
|
14
|
+
s.email = %q{jose@peleteiro.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/duration.rb",
|
26
|
+
"lib/duration/mongoid.rb",
|
27
|
+
"lib/ruby-duration.rb",
|
28
|
+
"ruby-duration.gemspec",
|
29
|
+
"test/duration/test_mongoid.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_duration.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/peleteiro/duration}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{Duration type}
|
38
|
+
s.test_files = [
|
39
|
+
"test/duration/test_mongoid.rb",
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/test_duration.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
53
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
57
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -5,11 +5,12 @@ class Duration::TestMongoid < MiniTest::Unit::TestCase
|
|
5
5
|
|
6
6
|
# Returns seconds to serialization
|
7
7
|
def test_get
|
8
|
-
assert_equal 90, Duration.
|
8
|
+
assert_equal Duration.new(90), Duration.get(90)
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_set_default
|
12
12
|
zero = Duration.new(0)
|
13
|
+
assert_equal zero, Duration.set([1,2,3])
|
13
14
|
assert_equal zero, Duration.set("string")
|
14
15
|
assert_equal zero, Duration.set(nil)
|
15
16
|
end
|
data/test/test_duration.rb
CHANGED
@@ -23,4 +23,14 @@ class TestDuration < MiniTest::Unit::TestCase
|
|
23
23
|
assert_equal 90, d.total
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_format_plural
|
27
|
+
d = Duration.new(:weeks => 2, :days => 3, :hours => 4, :minutes => 5, :seconds => 6)
|
28
|
+
assert_equal("2 weeks 3 days 4 hours 5 minutes 6 seconds", d.format("%w %~w %d %~d %h %~h %m %~m %s %~s"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_format_singular
|
32
|
+
d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :minutes => 1, :seconds => 1)
|
33
|
+
assert_equal("1 week 1 day 1 hour 1 minute 1 second", d.format("%w %~w %d %~d %h %~h %m %~m %s %~s"))
|
34
|
+
end
|
35
|
+
|
26
36
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jose Peleteiro
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-15 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/duration.rb
|
65
65
|
- lib/duration/mongoid.rb
|
66
66
|
- lib/ruby-duration.rb
|
67
|
+
- ruby-duration.gemspec
|
67
68
|
- test/duration/test_mongoid.rb
|
68
69
|
- test/helper.rb
|
69
70
|
- test/test_duration.rb
|