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: d9096b94ae18a9333ed3c0c62c5e073c25cd0fdc
4
- data.tar.gz: 147fe75ef459749f6ac2761ea89e27db2ad99412
3
+ metadata.gz: a3fee0e0d95938db84e9dbe97c3fa4532129043c
4
+ data.tar.gz: 4d6121fc8e91db199265e7e055d89d01187aad21
5
5
  SHA512:
6
- metadata.gz: eff8be4785754451bb00d48688e43674e114e09eb79ab568534db8134055a0ecae5e036c094f73cf9a686ebdd7112ea7754329ef3c3e246639adec174462135b
7
- data.tar.gz: 28295c08b4d64035a69b91ed21e1afab836b274d9fd2a7f3ae904d31291c82353e52ee6fa5c02868e6d034d1e77fe7128c3372edbb69d32a5834a945355207fd
6
+ metadata.gz: bc74c8df82a1cfbf6803a54ae6cb52315cf88526c69a7aeb82372e8af4302dba2c78bc473aad58e048a4d8675b07045b68d1806801713fc7ca6d6aeac6e03162
7
+ data.tar.gz: 7845adf7ce9cd5a03c3d1943ac76cfdc95f21410443988b271110179af52d4966f98c798baa60163106c3cfa7e563079655b8888f3b23aab417f7998e6b19f17
data/lib/percentable.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative 'percentable/version'
2
2
  require_relative 'percentable/numeric'
3
- require_relative 'percentable/applied_percent'
3
+ require_relative 'percentable/coerced_percent'
4
4
  require_relative 'percentable/percent'
5
5
  require_relative 'percentable/percentize'
@@ -1,4 +1,4 @@
1
- class AppliedPercent < Struct.new(:percent)
1
+ class CoercedPercent < Struct.new(:percent)
2
2
  def + other
3
3
  other + self * other
4
4
  end
@@ -40,8 +40,8 @@ module Percentable
40
40
  case other
41
41
  when Percent
42
42
  self.class.new(to_f * other.value)
43
- when Numeric
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
- [AppliedPercent.new(self), other]
75
+ [CoercedPercent.new(self), other]
76
76
  else
77
77
  fail TypeError, "#{self.class} can't be coerced into #{other.class}"
78
78
  end
@@ -1,3 +1,3 @@
1
1
  module Percentable
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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.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-08-14 00:00:00.000000000 Z
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/applied_percent.rb
85
+ - lib/percentable/coerced_percent.rb
86
86
  - lib/percentable/numeric.rb
87
87
  - lib/percentable/percent.rb
88
88
  - lib/percentable/percentize.rb