moolah 5.2.0 → 5.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d6d273ed7273e3e1f788c93369570aeed0f4b4040abb8d494b84b8f3a0eda21
4
- data.tar.gz: cc68a4a6bf14797382ef669ad34ef16decd87fdb7f11028067bffa62b59c9d11
3
+ metadata.gz: 259bd848b9c02a4cbec6ae4b48100192caff0c00b9315c82a6dd7b81372711cc
4
+ data.tar.gz: ac0a29f2335095310e45bc3a597d7a4c7db644e7f15d9262d0f05fd5717d1965
5
5
  SHA512:
6
- metadata.gz: 4bb4d5be819af9158b0b1491e62ed1b914fe410365168e31ca777b0e70e2e1e943da4337f6a7d6d38dab51dd2bdb8af4b4b3366d12b8c75a303f8646de59fa14
7
- data.tar.gz: d188591ef2f06d424d5ba5b4c34d6fc94a334e1c1ca3494db2ddd52ec24403842fd1fcfe0f525586435d22c6fdc6e94b0c2dbe53536f1d03cb18c9a8a315d281
6
+ metadata.gz: 706e6c87160955d2cc3cde1e238e79a7f6c0e2a66d2159591dd0227c4008e4ac30cf7aee1f235b0da3f771f3444393de86642390d50ee2d1f669d9837a1bd2a5
7
+ data.tar.gz: c2b621ca8644131cab99bdf0e13b16447e257472235c54917865bb03695e6af8b92f5343febef98296c69ca86cbecfdca5d95b52e0bd0991942edb9d2500aaed
data/lib/moolah/money.rb CHANGED
@@ -35,6 +35,10 @@ module Moolah
35
35
  formatter.format(symbol: false, delimit: false)
36
36
  end
37
37
 
38
+ def formatted_fx_rate
39
+ formatter.format_fx_rate
40
+ end
41
+
38
42
  def amount_in_cents
39
43
  (bankers_rounded.amount * 100).to_i
40
44
  end
@@ -57,18 +61,22 @@ module Moolah
57
61
 
58
62
  def +(money)
59
63
  return self unless money
60
- raise ArgumentError, 'Cannot add two Money objects with different currencies' if currency != money.currency
61
- raise ArgumentError, 'Cannot add two Money objects with different fx rates' if fx_rate != money.fx_rate
62
64
 
63
- Money.new(amount: amount + money.amount, currency: currency, fx_rate: fx_rate)
65
+ new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
66
+ raise ArgumentError, "Cannot add currency: #{currency} with given currency: #{new_money.currency}" if currency != new_money.currency
67
+ raise ArgumentError, "Cannot add fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
68
+
69
+ Money.new(amount: amount + new_money.amount, currency: currency, fx_rate: fx_rate)
64
70
  end
65
71
 
66
72
  def -(money)
67
73
  return self unless money
68
- raise ArgumentError, 'Cannot subtract two Money objects with different currencies' if currency != money.currency
69
- raise ArgumentError, 'Cannot subtract two Money objects with different fx rates' if fx_rate != money.fx_rate
70
74
 
71
- Money.new(amount: amount - money.amount, currency: currency, fx_rate: fx_rate)
75
+ new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
76
+ raise ArgumentError, "Cannot subtract currency: #{currency} with given currency: #{new_money.currency}" if currency != new_money.currency
77
+ raise ArgumentError, "Cannot subtract fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
78
+
79
+ Money.new(amount: amount - new_money.amount, currency: currency, fx_rate: fx_rate)
72
80
  end
73
81
 
74
82
  def *(_money)
@@ -84,10 +92,11 @@ module Moolah
84
92
  end
85
93
 
86
94
  def <=>(money)
87
- raise ArgumentError, 'Cannot compare two Money objects with different currencies' if currency != money.currency
88
- raise ArgumentError, 'Cannot compare two Money objects with different fx rates' if fx_rate != money.fx_rate
95
+ new_money = money.is_a?(Moolah::Money) ? money : Moolah::Money.new(money)
96
+ raise ArgumentError, "Cannot compare currency: #{currency} with given currency: #{money.currency}" if currency != new_money.currency
97
+ raise ArgumentError, "Cannot compare fx rate: #{formatter.format_fx_rate} with given fx rate: #{new_money.formatted_fx_rate}" if fx_rate != new_money.fx_rate
89
98
 
90
- amount <=> money.amount
99
+ amount <=> new_money.amount
91
100
  end
92
101
 
93
102
  def bankers_rounded
@@ -1,6 +1,6 @@
1
1
  module Moolah
2
2
  MAJOR = 5
3
- MINOR = 2
3
+ MINOR = 3
4
4
  PATCH = ENV['PATCH_VERSION'] || 0
5
5
 
6
6
  private_constant :MAJOR, :MINOR, :PATCH
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moolah
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Lee
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-19 00:00:00.000000000 Z
12
+ date: 2022-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler