shopify-money 1.1.0 → 1.1.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
  SHA256:
3
- metadata.gz: 2ee2b0d21b57f4ab542e863b1e4726ef3f6185968313750e2fcb5903a7c901b7
4
- data.tar.gz: 331d13d263aa4d502229ec33c3dfb098dbfa8892e3e8dca4a74774fe434f0178
3
+ metadata.gz: 68cd70a11908e256c3743d9cd5c66ad2d3fb93eac02fd7973a5e8c20c6ca3e6b
4
+ data.tar.gz: c5619ce2dc46b6271ae96c326c57b8d4fc7dfef9f3696db1f140c83b5df0f5bf
5
5
  SHA512:
6
- metadata.gz: 8e92eca63c1264797f09f09482ff0d02af00440f018c74a25341110f92db14d4ff105e25001f397c87b98241dadf0bd8eab6532f1faf01d7b1930bdef09038ce
7
- data.tar.gz: a1bf291e6a87b3d356711f5852399869bdb6478d508a16c2bd8a23acdeb7a94eb7ed6a24a47d7506ae1219960a80c49fabfcbbb26c5f5d7c969978819af62c34
6
+ metadata.gz: 116fc4ca873f7373653509bc104d8343160877c3085ac2446dacbb918ecf2e823a915b9f2bb97ab48d7a39c4f2515518fa64ffece7a2c501b4a3958ea5455457
7
+ data.tar.gz: 3b702aa16acd05f2100589ac319931c268999e616ce28e741c921539000c39b48521807c6a81d1a0aaaf70c2f436a02a4f236109104db00bd4cdb5b9c8e9c01e
data/lib/money/helpers.rb CHANGED
@@ -10,6 +10,7 @@ class Money
10
10
 
11
11
  STRIPE_SUBUNIT_OVERRIDE = {
12
12
  'ISK' => 100,
13
+ 'UGX' => 100,
13
14
  }.freeze
14
15
 
15
16
  def value_to_decimal(num)
data/lib/money/money.rb CHANGED
@@ -232,9 +232,12 @@ class Money
232
232
  if units == 0
233
233
  sprintf("%d", rounded_value)
234
234
  else
235
- sign = rounded_value < 0 ? '-' : ''
236
- rounded_value = rounded_value.abs
237
- sprintf("%s%d.%0#{units}d", sign, rounded_value.truncate, rounded_value.frac * (10 ** units))
235
+ formatted = rounded_value.to_s("F")
236
+ decimal_digits = formatted.size - formatted.index(".") - 1
237
+ (units - decimal_digits).times do
238
+ formatted << '0'
239
+ end
240
+ formatted
238
241
  end
239
242
  end
240
243
  alias_method :to_s, :to_fs
data/lib/money/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Money
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.2"
4
4
  end
data/spec/money_spec.rb CHANGED
@@ -376,6 +376,10 @@ RSpec.describe "Money" do
376
376
  expect(Money.from_subunits(100, 'ISK', format: :stripe)).to eq(Money.new(1, 'ISK'))
377
377
  end
378
378
 
379
+ it 'overrides the subunit_to_unit amount for UGX' do
380
+ expect(Money.from_subunits(100, 'UGX', format: :stripe)).to eq(Money.new(1, 'UGX'))
381
+ end
382
+
379
383
  it 'fallbacks to the default subunit_to_unit amount if no override is specified' do
380
384
  expect(Money.from_subunits(100, 'USD', format: :stripe)).to eq(Money.new(1, 'USD'))
381
385
  end
@@ -622,6 +626,10 @@ RSpec.describe "Money" do
622
626
  expect(Money.new(1, 'ISK').subunits(format: :stripe)).to eq(100)
623
627
  end
624
628
 
629
+ it 'overrides the subunit_to_unit amount for UGX' do
630
+ expect(Money.new(1, 'UGX').subunits(format: :stripe)).to eq(100)
631
+ end
632
+
625
633
  it 'fallbacks to the default subunit_to_unit amount if no override is specified' do
626
634
  expect(Money.new(1, 'USD').subunits(format: :stripe)).to eq(100)
627
635
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc