monetize 1.11.0 → 1.12.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: 10b41ae5e40bb51d6d3fae9eb49cdd73c7be8542dd80c43467a12483f1c8e63b
4
- data.tar.gz: 86ccb9489502a681cc271cca544eb2f1dbf9268034f1a7b83e2d1ddaa97d4f9a
3
+ metadata.gz: fec107ece48dc97d0e602c4176dc4bee8e9dd7be4172c0a507df4efa941ddc12
4
+ data.tar.gz: d15c4dd9bfc270948d69e6ffb9483baa9cde97743111d0fb68b3f6f1db8d6c9d
5
5
  SHA512:
6
- metadata.gz: c25475d1877bc00dceb06e01cb6863e4e805e87128320b6f77f2a7847930d22e1930ec9ee7cbe0f7efc462428348c05937121b2c45830cbf8f2003fd89dcd64c
7
- data.tar.gz: fe0a09adc661a2d4afbbc7ee7ee7327d55fef5be9045f8c54d487121e6cc7057d9b53e1fa3890abad382fb8a71e178c69da04a2d95c069cd07880ae22f5f6818
6
+ metadata.gz: 2bae292db1e6349b333248bab902017130ee85741e0321e8429216c83ca17c79003f36355eaced3e21fa8e9969df5a29f8fe538fe79ecef7f951b882f8cafe10
7
+ data.tar.gz: f5cc392537c1d8487c3117c680f9e49d0d38ec0db67fcda73594a4a7ce0dfddd8224338eaf5e97da880a86a5e31b4181fb287b9dd8b079f47ec104fd0edbfd49
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.12.0
4
+ - Update `to_money` to match money-rails to_hash.
5
+
3
6
  ## 1.11.0
4
7
  - When parsing a string assume a single separator to be a decimal mark when number starts with 0
5
8
 
@@ -2,7 +2,16 @@
2
2
 
3
3
  class Hash
4
4
  def to_money(currency = nil)
5
- hash_currency = self[:currency].is_a?(Hash) ? self[:currency][:iso_code] : self[:currency]
6
- Money.new(self[:cents] || self[:fractional], hash_currency || currency || Money.default_currency)
5
+ money_hash = self.respond_to?(:with_indifferent_access) ? self.with_indifferent_access : self
6
+
7
+ hash_currency = if money_hash[:currency].is_a?(Hash)
8
+ money_hash[:currency][:iso_code]
9
+ elsif money_hash[:currency_iso] && !money_hash[:currency_iso].empty?
10
+ money_hash[:currency_iso]
11
+ else
12
+ money_hash[:currency]
13
+ end
14
+
15
+ Money.new(money_hash[:cents] || money_hash[:fractional], hash_currency || currency || Money.default_currency)
7
16
  end
8
17
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Monetize
4
- VERSION = '1.11.0'
4
+ VERSION = '1.12.0'
5
5
  end
@@ -230,6 +230,14 @@ describe Monetize, 'core extensions' do
230
230
  expect(hash.to_money).to eq(Money.new(100, 'USD'))
231
231
  end
232
232
  end
233
+
234
+ context 'when Money to_hash is used' do
235
+ subject(:hash) { { cents: 100, currency_iso: 'SGD' } }
236
+
237
+ it 'converts Hash to Money, interpreting fractional as cents' do
238
+ expect(hash.to_money).to eq(Money.new(100, 'SGD'))
239
+ end
240
+ end
233
241
  end
234
242
  end
235
243
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-04 00:00:00.000000000 Z
12
+ date: 2022-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: money
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubygems_version: 3.2.3
124
+ rubygems_version: 3.2.22
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: A library for converting various objects into `Money` objects.