cashify 0.9.2 → 1.0.0

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
  SHA256:
3
- metadata.gz: 64931c6dfbe556f9be4e6df85acec0834356908a458b0f0a5902dd4860f255c7
4
- data.tar.gz: b253a94f16e2963ae778fab00462f1ba7afc5b4a40e4eee5509d8eb9473ff8e1
3
+ metadata.gz: bf06dc249f2461c5e6f7f59cdf2208eae3a423007570b12e5a52eaa8ed5ca44c
4
+ data.tar.gz: 625e22c82feb306c2564f5f7e79db25d6d658bfddaa347450b909bb7503b2fae
5
5
  SHA512:
6
- metadata.gz: 632eb24038223a070f5745265efe091c084d68148db0fa60d884c9837a02c99bf292cd719e1abc224309d67e11fd126a63518b8476e5224fecf4a0eacde9dab3
7
- data.tar.gz: a2c76193de484857fb7237a5ef16d9e3c479cca6ac1db3874f13223e035e1f417bc4d58baeb5fdb12d399d7e1f8c62a162c7656f32cde459a2226990671ca3c6
6
+ metadata.gz: 8f65af840ef4a53e2bf82bff63197526bbbfa22d936321b57ddabce52762fb02f7f55bfd3436306fd6af99bdd0882dfead0b5a323b613ff4b0c6bbae4d5bc032
7
+ data.tar.gz: 84c82bca4217c8a116c24a62cde33d9d0f12c6d2139f357ebb64633f7472f2c56bb566b89ae0e0094c0029bfe233655f25261c22a70ea7ee74776ef406efa3ea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.0.0] - 2023-03-30
2
+
3
+ - Add coercion so things like `sum` work natively (Johan Halse)
4
+
1
5
  ## [0.9.2] - 2022-11-18
2
6
 
3
7
  - Add `to_delimited_s` method (Johan Halse)
data/README.md CHANGED
@@ -161,15 +161,6 @@ Cash.new(EUR: 100_00, SEK: 100_00, USD: 100_00).to_s
161
161
  # "100 EUR, 100 SEK, 100 USD"
162
162
  ```
163
163
 
164
- #### `.sum`
165
-
166
- You'll be working with arrays of Cash objects a lot. You should absolutely be using Ruby's excellent array methods on them, but unfortunately `cash_array.sum` won't work. Ruby's `sum` method injects a `0` as the first value, and even though `Cash.new(USD: 100) + 0` is super valid and nice, `0 + Cash.new(USD: 100)` will try to coerce your Cash object into an integer which just won't work. So if you want to sum an array of Cash, you can instead use:
167
-
168
- ```ruby
169
- Cash.sum [Cash.new(EUR: 100_00), Cash.new(SEK: 100_00), Cash.new(EUR: 100_00)]
170
- # 200 EUR, 100 SEK
171
- ```
172
-
173
164
  #### `.empty?`
174
165
 
175
166
  Returns true if there are no currencies in the object.
@@ -1,5 +1,9 @@
1
1
  class Cash
2
2
  module Arithmetic
3
+ def coerce(other)
4
+ [self, other]
5
+ end
6
+
3
7
  def +(other)
4
8
  raise Cash::Errors::AdditionError unless other.respond_to?(:zero?)
5
9
  return self unless present?(other)
@@ -1,3 +1,3 @@
1
1
  module Cashify
2
- VERSION = "0.9.2".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
data/lib/cashify.rb CHANGED
@@ -25,10 +25,6 @@ class Cash
25
25
  new(USD: 0)
26
26
  end
27
27
 
28
- def self.sum(cashes)
29
- cashes.inject(Cash.zero, :+)
30
- end
31
-
32
28
  def initialize(**currencies)
33
29
  @currencies = currencies
34
30
  .transform_keys(&:to_sym)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cashify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Halse
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Money trouble no more! Add, subtract, and have fun with money in different
14
14
  currencies.
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubygems_version: 3.3.7
60
+ rubygems_version: 3.4.3
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: A sensible way to handle money