money 6.18.0 → 6.19.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: 146c73332b26929014c71519d1a698b06aa8782651787d363c3bf6a495e5b6c5
4
- data.tar.gz: 7dc290dc12bc060396c291d0b4f8615240d5e745d6dfb6ee493aec60296fceec
3
+ metadata.gz: 331d852b12ab9a5e62108f3610d1ec5eed8f4fa9bb683be1aab2703cd2df26cd
4
+ data.tar.gz: 56e2bcad250542c80b800db800c2216dd2b3b10f1df5d8a77819d13153a77844
5
5
  SHA512:
6
- metadata.gz: a732f1abb1cac4bfeabd12a8541ef88704da0db312ef1a93e625c738724e272ef1848eb60d5fe50910c21ab4de57937e20bc332a752daadb459865c249322892
7
- data.tar.gz: 4351c0c06eab76fdfff48a25447606513b525bc04c0cdb478bff472816b11e5d7c9201420e79c85a1697951678a1905530ee484a8c822412c93188c2853044f4
6
+ metadata.gz: ae6d529a7382aaab721a4ae933658828f975eaa4c9a0ad9444b74b28d8ff1141d59f3e264d08b650367e327987266be03dcd480e0a850fe224feb6cdca4163d1
7
+ data.tar.gz: bbb76570efd7bf4be700cc3f46d01e26945e9790f5f9f3fee666d4ac3164d1422f5ca1614622a429c430804a9047bcc8f5178886905e5ad814ce21ab4117f94a
data/CHANGELOG.md CHANGED
@@ -2,14 +2,25 @@
2
2
 
3
3
  ## Upcoming
4
4
 
5
- - Add second dobra (STN) from São Tomé and Príncipe
6
- - Use euro symbol as html_entity for euro currency
7
- - Update Georgian Lari symbol
8
- - Add Ruby 3.1 to the CI matrix
5
+ -
6
+
7
+ ## 6.19.0
8
+
9
+ - Change Peruvian Sol (PEN) decimal mark and thousands separator.
10
+ - Improves Precision and Simplifies Allocation Logic
11
+ - explicit declaration of i18n locales
12
+ - Add space to CHF format
13
+ - Update deprecation message to suggest correct formatting.
9
14
 
10
15
  ## 6.18.0
11
16
 
17
+ - Add second dobra (STN) from São Tomé and Príncipe
18
+ - Correct South African Rand (ZAR) to use comma decimal mark, and space thousands separator
19
+ - Use euro symbol as html_entity for euro currency
20
+ - Update Georgian Lari symbol
21
+ - Add Ruby 3.1 and 3.2 to the CI matrix
12
22
  - Add `Money.from_dollars` alias as a more explicit initializer, it's the same as `Money.from_amount`
23
+ - Mark Croatian Kuna (HRK) as obsolete by moving its definition to the backwards compatibility data source
13
24
 
14
25
  ## 6.17.0
15
26
 
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ MIT License
2
2
 
3
3
  Copyright (c) 2005 Tobias Lutke
4
4
  Copyright (c) 2008 Phusion
5
- Copyright (c) 2022 Shane Emmons
5
+ Copyright (c) 2024 Shane Emmons
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -60,6 +60,10 @@ The development version (hosted on Github) can be installed with:
60
60
  ``` ruby
61
61
  require 'money'
62
62
 
63
+ # explicitly define locales
64
+ I18n.config.available_locales = :en
65
+ Money.locale_backend = :i18n
66
+
63
67
  # 10.00 USD
64
68
  money = Money.from_cents(1000, "USD")
65
69
  money.cents #=> 1000
@@ -31,6 +31,22 @@
31
31
  "iso_numeric": "288",
32
32
  "smallest_denomination": 1
33
33
  },
34
+ "hrk": {
35
+ "priority": 100,
36
+ "iso_code": "HRK",
37
+ "name": "Croatian Kuna",
38
+ "symbol": "kn",
39
+ "alternate_symbols": [],
40
+ "subunit": "Lipa",
41
+ "subunit_to_unit": 100,
42
+ "symbol_first": false,
43
+ "format": "%n %u",
44
+ "html_entity": "",
45
+ "decimal_mark": ",",
46
+ "thousands_separator": ".",
47
+ "iso_numeric": "191",
48
+ "smallest_denomination": 1
49
+ },
34
50
  "ltl": {
35
51
  "priority": 100,
36
52
  "iso_code": "LTL",
@@ -452,7 +452,7 @@
452
452
  "subunit": "Rappen",
453
453
  "subunit_to_unit": 100,
454
454
  "symbol_first": true,
455
- "format": "%u%n",
455
+ "format": "%u %n",
456
456
  "html_entity": "",
457
457
  "decimal_mark": ".",
458
458
  "thousands_separator": ",",
@@ -922,22 +922,6 @@
922
922
  "iso_numeric": "340",
923
923
  "smallest_denomination": 5
924
924
  },
925
- "hrk": {
926
- "priority": 100,
927
- "iso_code": "HRK",
928
- "name": "Croatian Kuna",
929
- "symbol": "kn",
930
- "alternate_symbols": [],
931
- "subunit": "Lipa",
932
- "subunit_to_unit": 100,
933
- "symbol_first": false,
934
- "format": "%n %u",
935
- "html_entity": "",
936
- "decimal_mark": ",",
937
- "thousands_separator": ".",
938
- "iso_numeric": "191",
939
- "smallest_denomination": 1
940
- },
941
925
  "htg": {
942
926
  "priority": 100,
943
927
  "iso_code": "HTG",
@@ -1706,8 +1690,8 @@
1706
1690
  "subunit_to_unit": 100,
1707
1691
  "symbol_first": true,
1708
1692
  "html_entity": "S/",
1709
- "decimal_mark": ".",
1710
- "thousands_separator": ",",
1693
+ "decimal_mark": ",",
1694
+ "thousands_separator": ".",
1711
1695
  "iso_numeric": "604",
1712
1696
  "smallest_denomination": 1
1713
1697
  },
@@ -2695,8 +2679,8 @@
2695
2679
  "subunit_to_unit": 100,
2696
2680
  "symbol_first": true,
2697
2681
  "html_entity": "R",
2698
- "decimal_mark": ".",
2699
- "thousands_separator": ",",
2682
+ "decimal_mark": ",",
2683
+ "thousands_separator": " ",
2700
2684
  "iso_numeric": "710",
2701
2685
  "smallest_denomination": 10
2702
2686
  },
@@ -2,16 +2,17 @@
2
2
 
3
3
  class Money
4
4
  class Allocation
5
- # Splits a given amount in parts without losing pennies.
6
- # The left-over pennies will be distributed round-robin amongst the parts. This means that
7
- # parts listed first will likely receive more pennies than the ones listed later.
5
+ # Splits a given amount in parts. The allocation is based on the parts' proportions
6
+ # or evenly if parts are numerically specified.
8
7
  #
9
8
  # The results should always add up to the original amount.
10
9
  #
11
- # The parts can be specified as:
12
- # Numeric performs the split between a given number of parties evenely
13
- # Array<Numeric> allocates the amounts proportionally to the given array
10
+ # @param amount [Numeric] The total amount to be allocated.
11
+ # @param parts [Numeric, Array<Numeric>] Number of parts to split into or an array (proportions for allocation)
12
+ # @param whole_amounts [Boolean] Specifies whether to allocate whole amounts only. Defaults to true.
14
13
  #
14
+ # @return [Array<Numeric>] An array containing the allocated amounts.
15
+ # @raise [ArgumentError] If parts is empty or not provided.
15
16
  def self.generate(amount, parts, whole_amounts = true)
16
17
  parts = if parts.is_a?(Numeric)
17
18
  Array.new(parts, 1)
@@ -21,7 +22,12 @@ class Money
21
22
  parts.dup
22
23
  end
23
24
 
24
- raise ArgumentError, 'need at least one party' if parts.empty?
25
+ raise ArgumentError, 'need at least one part' if parts.empty?
26
+
27
+ if [amount, *parts].any? { |i| i.is_a?(BigDecimal) || i.is_a?(Float) || i.is_a?(Rational) }
28
+ amount = convert_to_big_decimal(amount)
29
+ parts.map! { |p| convert_to_big_decimal(p) }
30
+ end
25
31
 
26
32
  result = []
27
33
  remaining_amount = amount
@@ -42,5 +48,21 @@ class Money
42
48
 
43
49
  result
44
50
  end
51
+
52
+ # Converts a given number to BigDecimal.
53
+ # This method supports inputs of BigDecimal, Rational, and other numeric types by ensuring they are all returned
54
+ # as BigDecimal instances for consistent handling.
55
+ #
56
+ # @param number [Numeric, BigDecimal, Rational] The number to convert.
57
+ # @return [BigDecimal] The converted number as a BigDecimal.
58
+ def self.convert_to_big_decimal(number)
59
+ if number.is_a? BigDecimal
60
+ number
61
+ elsif number.is_a? Rational
62
+ BigDecimal(number.to_f.to_s)
63
+ else
64
+ BigDecimal(number.to_s)
65
+ end
66
+ end
45
67
  end
46
68
  end
@@ -117,7 +117,7 @@ class Money
117
117
  def warn_about_deprecated_rules(rules)
118
118
  if rules.has_key?(:symbol_position)
119
119
  position = rules[:symbol_position]
120
- template = position == :before ? '%u %n' : '%n %u'
120
+ template = position == :before ? '%u%n' : '%n%u'
121
121
 
122
122
  warn "[DEPRECATION] `symbol_position: :#{position}` is deprecated - you can replace it with `format: #{template}`"
123
123
  end
data/lib/money/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = '6.18.0'
2
+ VERSION = '6.19.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.18.0
4
+ version: 6.19.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: 2024-03-05 00:00:00.000000000 Z
12
+ date: 2024-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n