safe_money 0.0.1 → 0.0.2

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: 7043291fe6f136304f269d617f015cf639874775
4
- data.tar.gz: 941bc0966d50a64ecd0872e80563d6eec8ba9c3e
3
+ metadata.gz: b69cafcfb62af937e2270ed9969e08797884d96e
4
+ data.tar.gz: fea8491c28f6341ae2a0de134697c3dddb6a8f9c
5
5
  SHA512:
6
- metadata.gz: fe0bcb5313b7423ea74698472f6ce4a30d6d6df07fd3f584f97ba3c101363aef4b17b98f8a99858ce42a11cba007f942b349828015d8902ec977e3e4613977de
7
- data.tar.gz: 9d5d0c6cce93f4752acfa79cdcd93083c3a0f437f0e8f3573ec4a1ee5b663c7d287352dc94ef8b6936a481f2c1ace269f477c65e3caf84f1ad4f32c3a708148a
6
+ metadata.gz: 9965a3997e85e88aaa0678ac9bc30a9da28da9cbebce5e2a253aace7040c1c3a519c5585b3d1ea97d38a7e0264d963891b950978a8fbcf363fc0a820818be0eb
7
+ data.tar.gz: f3526d5228804257a30c5f3bcc6b79445227b0218d757c1f45fc69ccc4d28ff182171e35c1fc5c046974727962d57faae713e37bac7d932261bbfbd69e6978d8
data/README.md CHANGED
@@ -10,7 +10,7 @@ If you've ever represented money using floats or ints you've likely made a mista
10
10
 
11
11
  You've just split a penny in half. No good!
12
12
 
13
- If you're using integers you can make the same mistake but it's even harder to notice
13
+ If you're using integers you can make the same mistake but it's even harder to notice:
14
14
 
15
15
  ```ruby
16
16
  1099 / 2 # => 549
@@ -19,7 +19,7 @@ If you're using integers you can make the same mistake but it's even harder to n
19
19
  You've just thrown a penny into the well of bad math.
20
20
 
21
21
 
22
- Safe Money prevents you from making these sorts of mistakes
22
+ Safe Money prevents you from making these sorts of mistakes:
23
23
 
24
24
  ```ruby
25
25
  10.99.dollars / 2 # => SafeMoney::ArithmeticError: $10.99 cannot be safely divided by 2
@@ -64,7 +64,7 @@ And then execute:
64
64
 
65
65
  $ bundle
66
66
 
67
- Or install it yourself as:
67
+ Or, install it yourself as:
68
68
 
69
69
  $ gem install safe_money
70
70
 
@@ -45,7 +45,7 @@ class SafeMoney
45
45
  @cents
46
46
  end
47
47
 
48
- %w{ even? odd? zero? to_f < <= == > >= <=> eql? to_json coerce }.each do |method_name|
48
+ %w{ hash even? odd? zero? to_f < <= == > >= <=> to_json coerce }.each do |method_name|
49
49
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
50
50
  def #{method_name}(*args, &block)
51
51
  to_i.send(:#{method_name}, *args, &block)
@@ -53,6 +53,16 @@ class SafeMoney
53
53
  RUBY
54
54
  end
55
55
 
56
+ def eql? other
57
+ other = other.to_i if self.class === other
58
+ to_i.eql?(other)
59
+ end
60
+
61
+ def equal? other
62
+ other = other.to_i if self.class === other
63
+ to_i.equal?(other)
64
+ end
65
+
56
66
  def to_dollars
57
67
  (@cents * 0.01).round(2)
58
68
  end
@@ -1,3 +1,3 @@
1
1
  class SafeMoney
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -288,5 +288,20 @@ describe SafeMoney do
288
288
  expect( right ).to eq 1099.0
289
289
  end
290
290
 
291
+ # Equality
292
+
293
+ it 'treats identical amounts as equal numbers' do
294
+ a = 10.dollars
295
+ b = 10.dollars
296
+ expect( a ).to eq b
297
+ expect( a ).to equal b
298
+ expect( a ).to eq 1000
299
+ expect( a ).to equal 1000
300
+ expect( a.eql?(1000) ).to be true
301
+ expect( a.equal?(1000) ).to be true
302
+ expect( a.eql?(b) ).to be true
303
+ expect( a.equal?(b) ).to be true
304
+ expect( [a,b].uniq ).to eq [a]
305
+ end
291
306
 
292
307
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Grippe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: represent cents with safe arithmetic
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
77
- - ".rspec"
76
+ - .gitignore
77
+ - .rspec
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
@@ -94,17 +94,17 @@ require_paths:
94
94
  - lib
95
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - '>='
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - '>='
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.0.14
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: represent cents with safe arithmetic