big_money 1.2.1 → 1.2.2
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.yml +1 -1
- data/big_money.gemspec +2 -2
- data/lib/big_money.rb +8 -0
- data/test/test_big_money.rb +20 -0
- metadata +3 -3
data/VERSION.yml
CHANGED
data/big_money.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "big_money"
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shane Hanna", "Marshall Roch"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-21"
|
13
13
|
s.description = "BigDecimal backed amount of money in a particular currency."
|
14
14
|
s.email = ["shane.hanna@gmail.com", "mroch@cmu.edu"]
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/big_money.rb
CHANGED
@@ -86,6 +86,14 @@ class BigMoney
|
|
86
86
|
amount.nonzero? && self
|
87
87
|
end
|
88
88
|
|
89
|
+
def positive?
|
90
|
+
self > self.class.new(0, self.currency)
|
91
|
+
end
|
92
|
+
|
93
|
+
def negative?
|
94
|
+
self < self.class.new(0, self.currency)
|
95
|
+
end
|
96
|
+
|
89
97
|
def <=>(money)
|
90
98
|
money.kind_of?(self.class) ? (currency <=> money.currency).nonzero? || (amount <=> money.amount).nonzero? || 0 : nil
|
91
99
|
end
|
data/test/test_big_money.rb
CHANGED
@@ -100,6 +100,7 @@ class TestBigMoney < Test::Unit::TestCase
|
|
100
100
|
|
101
101
|
should 'zero?' do
|
102
102
|
assert_equal BigMoney.new(-1.05).zero?, false
|
103
|
+
assert_equal BigMoney.new(-1).zero?, false
|
103
104
|
assert_equal BigMoney.new(0).zero?, true
|
104
105
|
assert_equal BigMoney.new(0.0).zero?, true
|
105
106
|
assert_equal BigMoney.new(1).zero?, false
|
@@ -108,11 +109,30 @@ class TestBigMoney < Test::Unit::TestCase
|
|
108
109
|
|
109
110
|
should 'nonzero?' do
|
110
111
|
assert_equal BigMoney.new(-1.05).nonzero?, BigMoney.new(-1.05)
|
112
|
+
assert_equal BigMoney.new(-1).nonzero?, BigMoney.new(-1)
|
111
113
|
assert_equal BigMoney.new(0).nonzero?, nil
|
112
114
|
assert_equal BigMoney.new(0.0).nonzero?, nil
|
113
115
|
assert_equal BigMoney.new(1).nonzero?, BigMoney.new(1)
|
114
116
|
assert_equal BigMoney.new(1.05).nonzero?, BigMoney.new(1.05)
|
115
117
|
end
|
118
|
+
|
119
|
+
should 'negative?' do
|
120
|
+
assert_equal BigMoney.new(-1.05).negative?, true
|
121
|
+
assert_equal BigMoney.new(-1).negative?, true
|
122
|
+
assert_equal BigMoney.new(0).negative?, false
|
123
|
+
assert_equal BigMoney.new(0.0).negative?, false
|
124
|
+
assert_equal BigMoney.new(1).negative?, false
|
125
|
+
assert_equal BigMoney.new(1.05).negative?, false
|
126
|
+
end
|
127
|
+
|
128
|
+
should 'positive?' do
|
129
|
+
assert_equal BigMoney.new(-1.05).positive?, false
|
130
|
+
assert_equal BigMoney.new(-1).positive?, false
|
131
|
+
assert_equal BigMoney.new(0).positive?, false
|
132
|
+
assert_equal BigMoney.new(0.0).positive?, false
|
133
|
+
assert_equal BigMoney.new(1).positive?, true
|
134
|
+
assert_equal BigMoney.new(1.05).positive?, true
|
135
|
+
end
|
116
136
|
end
|
117
137
|
|
118
138
|
context 'serialization' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: big_money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jeweler
|
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
segments:
|
140
140
|
- 0
|
141
|
-
hash:
|
141
|
+
hash: 1256381880328552037
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
none: false
|
144
144
|
requirements:
|