percentable 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3fee0e0d95938db84e9dbe97c3fa4532129043c
|
4
|
+
data.tar.gz: 4d6121fc8e91db199265e7e055d89d01187aad21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc74c8df82a1cfbf6803a54ae6cb52315cf88526c69a7aeb82372e8af4302dba2c78bc473aad58e048a4d8675b07045b68d1806801713fc7ca6d6aeac6e03162
|
7
|
+
data.tar.gz: 7845adf7ce9cd5a03c3d1943ac76cfdc95f21410443988b271110179af52d4966f98c798baa60163106c3cfa7e563079655b8888f3b23aab417f7998e6b19f17
|
data/lib/percentable.rb
CHANGED
data/lib/percentable/percent.rb
CHANGED
@@ -40,8 +40,8 @@ module Percentable
|
|
40
40
|
case other
|
41
41
|
when Percent
|
42
42
|
self.class.new(to_f * other.value)
|
43
|
-
|
44
|
-
self.class.new(value * other)
|
43
|
+
else
|
44
|
+
self.class.new(value * other.to_f)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -72,7 +72,7 @@ module Percentable
|
|
72
72
|
def coerce other
|
73
73
|
case other
|
74
74
|
when Numeric
|
75
|
-
[
|
75
|
+
[CoercedPercent.new(self), other]
|
76
76
|
else
|
77
77
|
fail TypeError, "#{self.class} can't be coerced into #{other.class}"
|
78
78
|
end
|
data/lib/percentable/version.rb
CHANGED
@@ -222,6 +222,27 @@ describe Percentable::Percent do
|
|
222
222
|
expect(percent * numeric).to eq subject.class.new(40)
|
223
223
|
end
|
224
224
|
end
|
225
|
+
|
226
|
+
context 'multiplying anything else' do
|
227
|
+
let(:other_thing) { double }
|
228
|
+
let(:percent) { subject.class.new(20) }
|
229
|
+
|
230
|
+
context 'responds to to_f' do
|
231
|
+
before { allow(other_thing).to receive(:to_f).and_return 1.0 }
|
232
|
+
|
233
|
+
it "should return the float value times the percent" do
|
234
|
+
expect(percent * other_thing).to eq subject.class.new(20)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'does not respond to to_f' do
|
239
|
+
before { allow(other_thing).to receive(:to_f).and_raise(NoMethodError) }
|
240
|
+
|
241
|
+
it "should raise a no method error" do
|
242
|
+
expect { percent * other_thing }.to raise_error(NoMethodError)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
225
246
|
end
|
226
247
|
|
227
248
|
describe '#/' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percentable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,7 +82,7 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- lib/percentable.rb
|
85
|
-
- lib/percentable/
|
85
|
+
- lib/percentable/coerced_percent.rb
|
86
86
|
- lib/percentable/numeric.rb
|
87
87
|
- lib/percentable/percent.rb
|
88
88
|
- lib/percentable/percentize.rb
|