cashrb 1.2.2 → 1.3.0
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/README.md +2 -0
- data/Rakefile +3 -2
- data/cashrb.gemspec +2 -2
- data/lib/cashrb/cash.rb +8 -0
- data/test/test_cash.rb +23 -0
- metadata +30 -43
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
cashrb
|
2
2
|
======
|
3
3
|
|
4
|
+
[](http://travis-ci.org/semmons99/cashrb)
|
5
|
+
|
4
6
|
Lightweight money and currency handler for working with financial calculations.
|
5
7
|
Ensures precision without sacrificing speed. Eschews complexity by only
|
6
8
|
providing what you need to get your job done.
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
-
require '
|
2
|
+
require 'rubygems/package_task'
|
3
3
|
|
4
4
|
Rake::TestTask.new
|
5
|
+
task :default => :test
|
5
6
|
|
6
7
|
spec = Gem::Specification.load File.expand_path("../cashrb.gemspec", __FILE__)
|
7
|
-
gem =
|
8
|
+
gem = Gem::PackageTask.new(spec)
|
8
9
|
gem.define
|
data/cashrb.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cashrb"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.3.0"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Shane Emmons"]
|
6
6
|
s.email = ["semmons99@gmail.com"]
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.required_ruby_version = ">= 1.8.7"
|
12
12
|
s.required_rubygems_version = ">= 1.3.6"
|
13
13
|
|
14
|
-
s.
|
14
|
+
s.add_dependency "minitest", "~> 2.2.0"
|
15
15
|
|
16
16
|
s.files = Dir.glob("{lib,test}/**/*")
|
17
17
|
s.files += %w(CHANGELOG.md LICENSE README.md)
|
data/lib/cashrb/cash.rb
CHANGED
@@ -78,6 +78,10 @@ class Cash
|
|
78
78
|
Cash.new(@cents - value.cents, new_options)
|
79
79
|
end
|
80
80
|
|
81
|
+
def -@
|
82
|
+
Cash.new(-@cents, new_options)
|
83
|
+
end
|
84
|
+
|
81
85
|
def *(value)
|
82
86
|
Cash.new(@cents * bd(value), new_options)
|
83
87
|
end
|
@@ -102,6 +106,10 @@ class Cash
|
|
102
106
|
[Cash.new(quotient, new_options), Cash.new(remainder, new_options)]
|
103
107
|
end
|
104
108
|
|
109
|
+
def abs
|
110
|
+
Cash.new(@cents.abs, new_options)
|
111
|
+
end
|
112
|
+
|
105
113
|
def <=>(value)
|
106
114
|
@cents <=> value.cents
|
107
115
|
end
|
data/test/test_cash.rb
CHANGED
@@ -174,6 +174,21 @@ class TestCash < MiniTest::Unit::TestCase
|
|
174
174
|
assert_equal Cash.new(5), rs
|
175
175
|
end
|
176
176
|
|
177
|
+
def test_unary_minus
|
178
|
+
rs = -Cash.new(6)
|
179
|
+
assert_equal Cash.new(-6), rs
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_unary_minus_with_modified_defaults
|
183
|
+
Cash.default_cents_in_whole = 10
|
184
|
+
Cash.default_rounding_method = BigDecimal::ROUND_UP
|
185
|
+
Cash.default_currency = :usd
|
186
|
+
Cash.default_from = :decimal
|
187
|
+
|
188
|
+
rs = -Cash.new(6)
|
189
|
+
assert_equal Cash.new(-6), rs
|
190
|
+
end
|
191
|
+
|
177
192
|
def test_multiply_with_Cash_Numeric
|
178
193
|
rs = Cash.new(6) * 2
|
179
194
|
assert_equal Cash.new(12), rs
|
@@ -267,6 +282,14 @@ class TestCash < MiniTest::Unit::TestCase
|
|
267
282
|
assert_equal [Cash.new(0.1), Cash.new(2)], rs
|
268
283
|
end
|
269
284
|
|
285
|
+
def test_abs_with_positive_cents
|
286
|
+
assert_equal Cash.new(120), Cash.new(120).abs
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_abs_with_negative_cents
|
290
|
+
assert_equal Cash.new(120), Cash.new(-120).abs
|
291
|
+
end
|
292
|
+
|
270
293
|
def test_equal_to_when_equal_to
|
271
294
|
rs = Cash.new(6) == Cash.new(6)
|
272
295
|
assert rs
|
metadata
CHANGED
@@ -1,33 +1,34 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cashrb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
- 2
|
10
|
-
version: 1.2.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Shane Emmons
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2011-11-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &16572528 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *16572528
|
21
25
|
description: Lightweight money and currency handler for working with financial calculations.
|
22
|
-
email:
|
26
|
+
email:
|
23
27
|
- semmons99@gmail.com
|
24
28
|
executables: []
|
25
|
-
|
26
29
|
extensions: []
|
27
|
-
|
28
30
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
31
|
+
files:
|
31
32
|
- lib/cashrb/cash.rb
|
32
33
|
- lib/cashrb.rb
|
33
34
|
- test/test_cash.rb
|
@@ -39,40 +40,26 @@ files:
|
|
39
40
|
- cashrb.gemspec
|
40
41
|
homepage: http://semmons99.github.com/cashrb/
|
41
42
|
licenses: []
|
42
|
-
|
43
43
|
post_install_message:
|
44
44
|
rdoc_options: []
|
45
|
-
|
46
|
-
require_paths:
|
45
|
+
require_paths:
|
47
46
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
48
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
hash: 57
|
54
|
-
segments:
|
55
|
-
- 1
|
56
|
-
- 8
|
57
|
-
- 7
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
58
52
|
version: 1.8.7
|
59
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
54
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
hash: 23
|
65
|
-
segments:
|
66
|
-
- 1
|
67
|
-
- 3
|
68
|
-
- 6
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
69
58
|
version: 1.3.6
|
70
|
-
requirements:
|
71
|
-
- minitest
|
59
|
+
requirements: []
|
72
60
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.5
|
74
62
|
signing_key:
|
75
63
|
specification_version: 3
|
76
64
|
summary: Lightweight money and currency handler for working with financial calculations.
|
77
65
|
test_files: []
|
78
|
-
|