cashrb 1.1.0 → 1.1.1
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/CHANGELOG.md +4 -0
- data/cashrb.gemspec +1 -1
- data/lib/cashrb/cash.rb +2 -2
- data/test/test_cash.rb +8 -0
- metadata +3 -5
data/CHANGELOG.md
CHANGED
data/cashrb.gemspec
CHANGED
data/lib/cashrb/cash.rb
CHANGED
@@ -78,7 +78,7 @@ class Cash
|
|
78
78
|
return self.cents.to_s if @cents_in_whole == 1
|
79
79
|
|
80
80
|
dollars, cents = dollars_and_cents
|
81
|
-
"#{dollars}.#{formatted_cents(cents)}"
|
81
|
+
"#{"-" if @cents < 0}#{dollars}.#{formatted_cents(cents)}"
|
82
82
|
end
|
83
83
|
|
84
84
|
def to_f
|
@@ -103,7 +103,7 @@ class Cash
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def dollars_and_cents
|
106
|
-
@cents.divmod(@cents_in_whole).map(&:to_i)
|
106
|
+
@cents.abs.divmod(@cents_in_whole).map(&:to_i)
|
107
107
|
end
|
108
108
|
|
109
109
|
def formatted_cents(cents)
|
data/test/test_cash.rb
CHANGED
@@ -275,6 +275,10 @@ class TestCash < MiniTest::Unit::TestCase
|
|
275
275
|
assert_equal "1.000", Cash.new(1000, :cents_in_whole => 1000).to_s
|
276
276
|
end
|
277
277
|
|
278
|
+
def test_to_s_with_negative_cents
|
279
|
+
assert_equal "-6338.33", Cash.new(-633833).to_s
|
280
|
+
end
|
281
|
+
|
278
282
|
def test_to_f
|
279
283
|
assert_equal 0.0, Cash.new(0 ).to_f
|
280
284
|
assert_equal 0.01, Cash.new(1 ).to_f
|
@@ -297,4 +301,8 @@ class TestCash < MiniTest::Unit::TestCase
|
|
297
301
|
assert_equal 1.0, Cash.new(1000, :cents_in_whole => 1000).to_f
|
298
302
|
end
|
299
303
|
|
304
|
+
def test_to_f_with_negative_cents
|
305
|
+
assert_equal -6338.33, Cash.new(-633833).to_f
|
306
|
+
end
|
307
|
+
|
300
308
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cashrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-04-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-04-08 00:00:00.000000000Z
|
14
13
|
dependencies: []
|
15
14
|
description: Dead simple gem to work with Money/Currency without the hassle of Floats
|
16
15
|
email:
|
@@ -28,7 +27,6 @@ files:
|
|
28
27
|
- Rakefile
|
29
28
|
- .gemtest
|
30
29
|
- cashrb.gemspec
|
31
|
-
has_rdoc: true
|
32
30
|
homepage: http://github.com/semmons99/cashrb
|
33
31
|
licenses: []
|
34
32
|
post_install_message:
|
@@ -50,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
48
|
requirements:
|
51
49
|
- minitest
|
52
50
|
rubyforge_project:
|
53
|
-
rubygems_version: 1.
|
51
|
+
rubygems_version: 1.7.2
|
54
52
|
signing_key:
|
55
53
|
specification_version: 3
|
56
54
|
summary: Dead simple gem to work with Money/Currency without the hassle of Floats
|