ruby-duration 0.1.6 → 0.1.7
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/VERSION +1 -1
- data/lib/duration.rb +1 -0
- data/lib/duration/mongoid.rb +4 -1
- data/ruby-duration.gemspec +1 -1
- data/test/duration/test_mongoid.rb +21 -9
- data/test/test_duration.rb +4 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/duration.rb
CHANGED
data/lib/duration/mongoid.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'duration'
|
3
|
+
require 'active_support/core_ext'
|
3
4
|
|
4
5
|
class Duration
|
5
6
|
def self.get(seconds)
|
7
|
+
return if !seconds
|
6
8
|
Duration.new(seconds)
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.set(args)
|
12
|
+
return if args.blank?
|
10
13
|
if args.is_a?(Hash)
|
11
14
|
Duration.new(args).to_i
|
12
15
|
elsif args.respond_to?(:to_i)
|
13
16
|
args.to_i
|
14
17
|
else
|
15
|
-
|
18
|
+
nil
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
data/ruby-duration.gemspec
CHANGED
@@ -4,24 +4,36 @@ require 'helper'
|
|
4
4
|
class Duration::TestMongoid < MiniTest::Unit::TestCase
|
5
5
|
|
6
6
|
# Returns seconds to serialization
|
7
|
-
def
|
7
|
+
def test_get_seconds
|
8
8
|
assert_equal Duration.new(90), Duration.get(90)
|
9
9
|
end
|
10
|
+
|
11
|
+
def test_get_nil
|
12
|
+
assert_nil Duration.get(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_set_nil
|
16
|
+
assert_nil Duration.set([1,2,3])
|
17
|
+
assert_nil Duration.set(nil)
|
18
|
+
assert_nil Duration.set("")
|
19
|
+
end
|
10
20
|
|
11
|
-
def
|
12
|
-
|
13
|
-
assert_equal zero, Duration.set([1,2,3])
|
14
|
-
assert_equal zero, Duration.set("string")
|
15
|
-
assert_equal zero, Duration.set(nil)
|
21
|
+
def test_set_duration
|
22
|
+
assert_equal 90, Duration.set(Duration.new(:minutes => 1, :seconds => 30))
|
16
23
|
end
|
17
24
|
|
18
25
|
def test_set_seconds
|
19
|
-
assert_equal
|
20
|
-
|
26
|
+
assert_equal 10, Duration.set(10)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_set_string
|
30
|
+
assert_equal 10, Duration.set("10")
|
31
|
+
assert_equal 10, Duration.set("10string")
|
32
|
+
assert_equal 0, Duration.set("string")
|
21
33
|
end
|
22
34
|
|
23
35
|
def test_set_hash
|
24
|
-
assert_equal
|
36
|
+
assert_equal 90, Duration.set(:minutes => 1, :seconds => 30)
|
25
37
|
end
|
26
38
|
|
27
39
|
end
|
data/test/test_duration.rb
CHANGED
@@ -39,13 +39,13 @@ class TestDuration < MiniTest::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_blank?
|
42
|
-
|
43
|
-
|
42
|
+
assert Duration.new.blank?
|
43
|
+
refute Duration.new(1).blank?
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_present?
|
47
|
-
|
48
|
-
|
47
|
+
refute Duration.new.present?
|
48
|
+
assert Duration.new(1).present?
|
49
49
|
end
|
50
50
|
|
51
51
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jose Peleteiro
|