ruby-duration 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
data/lib/duration.rb CHANGED
@@ -64,6 +64,7 @@ class Duration
64
64
 
65
65
  # Compare this duration to another (or objects that respond to #to_i)
66
66
  def <=>(other)
67
+ return false unless other.is_a?(Duration)
67
68
  @total <=> other.to_i
68
69
  end
69
70
 
@@ -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
- 0
18
+ nil
16
19
  end
17
20
  end
18
21
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-duration}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jose Peleteiro"]
@@ -4,24 +4,36 @@ require 'helper'
4
4
  class Duration::TestMongoid < MiniTest::Unit::TestCase
5
5
 
6
6
  # Returns seconds to serialization
7
- def test_get
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 test_set_default
12
- zero = Duration.new(0)
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 Duration.new(10), Duration.set("10")
20
- assert_equal Duration.new(10), Duration.set(10)
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 Duration.new(:minutes => 1, :seconds => 30), Duration.set(:minutes => 1, :seconds => 30)
36
+ assert_equal 90, Duration.set(:minutes => 1, :seconds => 30)
25
37
  end
26
38
 
27
39
  end
@@ -39,13 +39,13 @@ class TestDuration < MiniTest::Unit::TestCase
39
39
  end
40
40
 
41
41
  def test_blank?
42
- assert_true Duration.new.blank?
43
- assert_false Duration.new(1).blank?
42
+ assert Duration.new.blank?
43
+ refute Duration.new(1).blank?
44
44
  end
45
45
 
46
46
  def test_present?
47
- assert_false Duration.new.present?
48
- assert_true Duration.new(1).present?
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jose Peleteiro