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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/monetize/core_extensions/hash.rb +11 -2
- data/lib/monetize/version.rb +1 -1
- data/spec/core_extensions_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fec107ece48dc97d0e602c4176dc4bee8e9dd7be4172c0a507df4efa941ddc12
|
4
|
+
data.tar.gz: d15c4dd9bfc270948d69e6ffb9483baa9cde97743111d0fb68b3f6f1db8d6c9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bae292db1e6349b333248bab902017130ee85741e0321e8429216c83ca17c79003f36355eaced3e21fa8e9969df5a29f8fe538fe79ecef7f951b882f8cafe10
|
7
|
+
data.tar.gz: f5cc392537c1d8487c3117c680f9e49d0d38ec0db67fcda73594a4a7ce0dfddd8224338eaf5e97da880a86a5e31b4181fb287b9dd8b079f47ec104fd0edbfd49
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,16 @@
|
|
2
2
|
|
3
3
|
class Hash
|
4
4
|
def to_money(currency = nil)
|
5
|
-
|
6
|
-
|
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
|
data/lib/monetize/version.rb
CHANGED
@@ -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.
|
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:
|
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.
|
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.
|