cash 0.1.0 → 0.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/cash.gemspec +1 -1
- data/lib/cash.rb +7 -0
- data/spec/lib/cash_spec.rb +14 -0
- metadata +4 -4
data/cash.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "cash"
|
7
|
-
gem.version = '0.1.
|
7
|
+
gem.version = '0.1.1'
|
8
8
|
gem.authors = ["Norbert Wojtowicz"]
|
9
9
|
gem.email = ["wojtowicz.norbert@gmail.com"]
|
10
10
|
gem.description = "Money model backed by BigDecimal"
|
data/lib/cash.rb
CHANGED
@@ -60,6 +60,13 @@ class Cash
|
|
60
60
|
Cash.new(amount - o.amount, currency)
|
61
61
|
end
|
62
62
|
|
63
|
+
def *(factor)
|
64
|
+
factor = StrictDecimal(factor)
|
65
|
+
Cash.new(amount * factor, currency)
|
66
|
+
rescue ArgumentError
|
67
|
+
raise ArgumentError, "cannot multiply #{self.inspect} by #{factor}"
|
68
|
+
end
|
69
|
+
|
63
70
|
protected
|
64
71
|
|
65
72
|
def equality_state
|
data/spec/lib/cash_spec.rb
CHANGED
@@ -154,6 +154,20 @@ describe Cash do
|
|
154
154
|
expect{ three_usd - two_pln }.to raise_error(TypeError)
|
155
155
|
end
|
156
156
|
end
|
157
|
+
|
158
|
+
describe 'multiplication' do
|
159
|
+
it 'multiplies amount by bigdecimal' do
|
160
|
+
double = one_usd * 2
|
161
|
+
double.should == Cash.new(2, :usd)
|
162
|
+
|
163
|
+
tax = three_usd * BigDecimal.new('0.17')
|
164
|
+
tax.should == Cash.new('0.51', :usd)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'fails if multiplying cash by cash' do
|
168
|
+
expect{ one_usd * one_usd }.to raise_error(ArgumentError)
|
169
|
+
end
|
170
|
+
end
|
157
171
|
end
|
158
172
|
|
159
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
segments:
|
81
81
|
- 0
|
82
|
-
hash:
|
82
|
+
hash: 269915481050317062
|
83
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
segments:
|
90
90
|
- 0
|
91
|
-
hash:
|
91
|
+
hash: 269915481050317062
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
94
|
rubygems_version: 1.8.23
|