money 7.0.2 → 7.1.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +1 -0
  4. data/config/currency_iso.json +4 -4
  5. data/lib/money/bank/base.rb +3 -7
  6. data/lib/money/bank/single_currency.rb +2 -3
  7. data/lib/money/bank/variable_exchange.rb +34 -37
  8. data/lib/money/currency/heuristics.rb +1 -1
  9. data/lib/money/currency/loader.rb +1 -1
  10. data/lib/money/currency.rb +53 -32
  11. data/lib/money/locale_backend/base.rb +1 -1
  12. data/lib/money/locale_backend/currency.rb +1 -1
  13. data/lib/money/locale_backend/i18n.rb +6 -4
  14. data/lib/money/money/allocation.rb +10 -9
  15. data/lib/money/money/arithmetic.rb +34 -25
  16. data/lib/money/money/constructors.rb +5 -6
  17. data/lib/money/money/formatter.rb +25 -20
  18. data/lib/money/money/formatting_rules.rb +4 -2
  19. data/lib/money/money/locale_backend.rb +4 -4
  20. data/lib/money/money.rb +25 -30
  21. data/lib/money/rates_store/memory.rb +5 -8
  22. data/lib/money/version.rb +1 -1
  23. data/money.gemspec +7 -7
  24. data/sig/lib/money/bank/base.rbs +117 -0
  25. data/sig/lib/money/bank/single_currency.rbs +15 -0
  26. data/sig/lib/money/bank/variable_exchange.rbs +198 -0
  27. data/sig/lib/money/currency/heuristics.rbs +8 -0
  28. data/sig/lib/money/currency.rbs +322 -0
  29. data/sig/lib/money/locale_backend/base.rbs +6 -0
  30. data/sig/lib/money/locale_backend/errors.rbs +9 -0
  31. data/sig/lib/money/locale_backend/i18n.rbs +11 -0
  32. data/sig/lib/money/money/allocation.rbs +24 -0
  33. data/sig/lib/money/money/arithmetic.rbs +225 -0
  34. data/sig/lib/money/money/constructors.rbs +73 -0
  35. data/sig/lib/money/money/formatter.rbs +214 -0
  36. data/sig/lib/money/money/formatting_rules.rbs +32 -0
  37. data/sig/lib/money/money/locale_backend.rbs +7 -0
  38. data/sig/lib/money/money.rbs +522 -0
  39. data/sig/lib/money/rates_store/memory.rbs +90 -0
  40. data/sig/manifest.yaml +10 -0
  41. metadata +20 -6
@@ -0,0 +1,117 @@
1
+ class Money
2
+ # Provides classes that aid in the ability of exchange one currency with
3
+ # another.
4
+ module Bank
5
+ # The lowest Money::Bank error class.
6
+ # All Money::Bank errors should inherit from it.
7
+ class Error < StandardError
8
+ end
9
+
10
+ # Raised when the bank doesn't know about the conversion rate
11
+ # for specified currencies.
12
+ class UnknownRate < Error
13
+ end
14
+
15
+ # Money::Bank::Base is the basic interface for creating a money exchange
16
+ # object, also called Bank.
17
+ #
18
+ # A Bank is responsible for storing exchange rates, take a Money object as
19
+ # input and returns the corresponding Money object converted into an other
20
+ # currency.
21
+ #
22
+ # This class exists for aiding in the creating of other classes to exchange
23
+ # money between different currencies. When creating a subclass you will
24
+ # need to implement the following methods to exchange money between
25
+ # currencies:
26
+ #
27
+ # - #exchange_with(Money) #=> Money
28
+ #
29
+ # See Money::Bank::VariableExchange for a real example.
30
+ #
31
+ # Also, you can extend +Money::Bank::VariableExchange+ instead of
32
+ # +Money::Bank::Base+ if your bank implementation needs to store rates
33
+ # internally.
34
+ #
35
+ # @abstract Subclass and override +#exchange_with+ to implement a custom
36
+ # +Money::Bank+ class. You can also override +#setup+ instead of
37
+ # +#initialize+ to setup initial variables, etc.
38
+ class Base
39
+ @singleton: Money::Bank::Base
40
+
41
+ # Returns the singleton instance of the Base bank.
42
+ #
43
+ # @return [Money::Bank::Base]
44
+ def self.instance: () -> Money::Bank::Base
45
+
46
+ # The rounding method to use when exchanging rates.
47
+ #
48
+ # @return [Proc]
49
+ attr_reader rounding_method: untyped
50
+
51
+ # Initializes a new +Money::Bank::Base+ object. An optional block can be
52
+ # passed to dictate the rounding method that +#exchange_with+ can use.
53
+ #
54
+ # @yield [n] Optional block to use when rounding after exchanging one
55
+ # currency for another.
56
+ # @yieldparam [Float] n The resulting float after exchanging one currency
57
+ # for another.
58
+ # @yieldreturn [Integer]
59
+ #
60
+ # @return [Money::Bank::Base]
61
+ #
62
+ # @example
63
+ # Money::Bank::Base.new #=> #<Money::Bank::Base @rounding_method=nil>
64
+ # Money::Bank::Base.new {|n|
65
+ # n.floor
66
+ # } #=> #<Money::Bank::Base @round_method=#<Proc>>
67
+ def initialize: () { () -> untyped } -> void
68
+
69
+ # Called after initialize. Subclasses can use this method to setup
70
+ # variables, etc that they normally would in +#initialize+.
71
+ #
72
+ # @abstract Subclass and override +#setup+ to implement a custom
73
+ # +Money::Bank+ class.
74
+ #
75
+ # @return [self]
76
+ def setup: () -> nil
77
+
78
+ # Exchanges the given +Money+ object to a new +Money+ object in
79
+ # +to_currency+.
80
+ #
81
+ # @abstract Subclass and override +#exchange_with+ to implement a custom
82
+ # +Money::Bank+ class.
83
+ #
84
+ # @raise NotImplementedError
85
+ #
86
+ # @param [Money] from The +Money+ object to exchange from.
87
+ # @param [Money::Currency, String, Symbol] to_currency The currency
88
+ # string or object to exchange to.
89
+ # @yield [n] Optional block to use to round the result after making
90
+ # the exchange.
91
+ # @yieldparam [Float] n The result after exchanging from one currency to
92
+ # the other.
93
+ # @yieldreturn [Integer]
94
+ #
95
+ # @return [Money]
96
+ def exchange_with: (Money from, (Money::Currency | string | Symbol) to_currency) { () -> int } -> Money
97
+
98
+ # Given two currency strings or object, checks whether they're both the
99
+ # same currency. Return +true+ if the currencies are the same, +false+
100
+ # otherwise.
101
+ #
102
+ # @param [Money::Currency, String, Symbol] currency1 The first currency
103
+ # to compare.
104
+ # @param [Money::Currency, String, Symbol] currency2 The second currency
105
+ # to compare.
106
+ #
107
+ # @return [Boolean]
108
+ #
109
+ # @example
110
+ # same_currency?("usd", "USD") #=> true
111
+ # same_currency?("usd", "EUR") #=> false
112
+ # same_currency?("usd", Currency.new("USD")) #=> true
113
+ # same_currency?("usd", "USD") #=> true
114
+ def same_currency?: ((Money::Currency | string | Symbol) currency1, (Money::Currency | string | Symbol) currency2) -> bool
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,15 @@
1
+ class Money
2
+ module Bank
3
+ # Raised when trying to exchange currencies
4
+ class DifferentCurrencyError < Error
5
+ end
6
+
7
+ # Class to ensure client code is operating in a single currency
8
+ # by raising if an exchange attempts to happen.
9
+ class SingleCurrency < Base
10
+ # Raises a DifferentCurrencyError to remove possibility of accidentally
11
+ # exchanging currencies
12
+ def exchange_with: (Money from, (Money::Currency | string | Symbol) to_currency) ?{ (untyped) -> untyped } -> untyped
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,198 @@
1
+ class Money
2
+ module Bank
3
+ # Thrown when an unknown rate format is requested.
4
+ class UnknownRateFormat < StandardError
5
+ end
6
+
7
+ # Class for aiding in exchanging money between different currencies. By
8
+ # default, the +Money+ class uses an object of this class (accessible
9
+ # through +Money#bank+) for performing currency exchanges.
10
+ #
11
+ # By default, +Money::Bank::VariableExchange+ has no knowledge about
12
+ # conversion rates. One must manually specify them with +add_rate+, after
13
+ # which one can perform exchanges with +#exchange_with+.
14
+ #
15
+ # Exchange rates are stored in memory using +Money::RatesStore::Memory+ by default.
16
+ # Pass custom rates stores for other types of storage (file, database, etc)
17
+ #
18
+ # @example
19
+ # bank = Money::Bank::VariableExchange.new
20
+ # bank.add_rate("USD", "CAD", 1.24515)
21
+ # bank.add_rate("CAD", "USD", 0.803115)
22
+ #
23
+ # c1 = Money.new(100_00, "USD")
24
+ # c2 = Money.new(100_00, "CAD")
25
+ #
26
+ # # Exchange 100 USD to CAD:
27
+ # bank.exchange_with(c1, "CAD") #=> #<Money fractional:12451 currency:CAD>
28
+ #
29
+ # # Exchange 100 CAD to USD:
30
+ # bank.exchange_with(c2, "USD") #=> #<Money fractional:8031 currency:USD>
31
+ #
32
+ # # With custom exchange rates storage
33
+ # redis_store = MyCustomRedisStore.new(host: 'localhost:6379')
34
+ # bank = Money::Bank::VariableExchange.new(redis_store)
35
+ # # Store rates in redis
36
+ # bank.add_rate 'USD', 'CAD', 0.98
37
+ # # Get rate from redis
38
+ # bank.get_rate 'USD', 'CAD'
39
+ class VariableExchange < Base
40
+ attr_reader mutex: untyped
41
+
42
+ # Available formats for importing/exporting rates.
43
+ RATE_FORMATS: Array[Symbol]
44
+
45
+ SERIALIZER_SEPARATOR: string
46
+
47
+ FORMAT_SERIALIZERS: Hash[Symbol, (JSON | Marshal | YAML)]
48
+
49
+ # Initializes a new +Money::Bank::VariableExchange+ object.
50
+ # It defaults to using an in-memory, thread safe store instance for
51
+ # storing exchange rates.
52
+ #
53
+ # @param [RateStore] st An exchange rate store, used to persist exchange rate pairs.
54
+ # @yield [n] Optional block to use when rounding after exchanging one
55
+ # currency for another. See +Money::bank::base+
56
+ def initialize: (?untyped st) { () -> untyped } -> void
57
+
58
+ def store: () -> untyped
59
+
60
+ def marshal_dump: () -> ::Array[untyped]
61
+
62
+ def marshal_load: (untyped arr) -> untyped
63
+
64
+ # Exchanges the given +Money+ object to a new +Money+ object in
65
+ # +to_currency+.
66
+ #
67
+ # @param [Money] from
68
+ # The +Money+ object to exchange.
69
+ # @param [Currency, String, Symbol] to_currency
70
+ # The currency to exchange to.
71
+ #
72
+ # @yield [n] Optional block to use when rounding after exchanging one
73
+ # currency for another.
74
+ # @yieldparam [Float] n The resulting float after exchanging one currency
75
+ # for another.
76
+ # @yieldreturn [Integer]
77
+ #
78
+ # @return [Money]
79
+ #
80
+ # @raise +Money::Bank::UnknownRate+ if the conversion rate is unknown.
81
+ #
82
+ # @example
83
+ # bank = Money::Bank::VariableExchange.new
84
+ # bank.add_rate("USD", "CAD", 1.24515)
85
+ # bank.add_rate("CAD", "USD", 0.803115)
86
+ #
87
+ # c1 = Money.new(100_00, "USD")
88
+ # c2 = Money.new(100_00, "CAD")
89
+ #
90
+ # # Exchange 100 USD to CAD:
91
+ # bank.exchange_with(c1, "CAD") #=> #<Money fractional:12451 currency:CAD>
92
+ #
93
+ # # Exchange 100 CAD to USD:
94
+ # bank.exchange_with(c2, "USD") #=> #<Money fractional:8031 currency:USD>
95
+ def exchange_with: (Money from, (Money::Currency | string | Symbol) to_currency) { () -> int } -> Money
96
+
97
+ def calculate_fractional: (untyped from, untyped to_currency) -> untyped
98
+
99
+ def exchange: (untyped fractional, untyped rate) ?{ (untyped) -> untyped } -> untyped
100
+
101
+ # Registers a conversion rate and returns it (uses +#set_rate+).
102
+ # Delegates to +Money::RatesStore::Memory+
103
+ #
104
+ # @param [Currency, String, Symbol] from Currency to exchange from.
105
+ # @param [Currency, String, Symbol] to Currency to exchange to.
106
+ # @param [Numeric] rate Rate to use when exchanging currencies.
107
+ #
108
+ # @return [Numeric]
109
+ #
110
+ # @example
111
+ # bank = Money::Bank::VariableExchange.new
112
+ # bank.add_rate("USD", "CAD", 1.24515)
113
+ # bank.add_rate("CAD", "USD", 0.803115)
114
+ def add_rate: ((Money::Currency | string | Symbol) from, (Money::Currency | string | Symbol) to, Numeric rate) -> Numeric
115
+
116
+ # Set the rate for the given currencies.
117
+ # access.
118
+ # Delegates to +Money::RatesStore::Memory+
119
+ #
120
+ # @param [Currency, String, Symbol] from Currency to exchange from.
121
+ # @param [Currency, String, Symbol] to Currency to exchange to.
122
+ # @param [Numeric] rate Rate to use when exchanging currencies.
123
+ # @param [Hash] opts Options hash to set special parameters. Backwards compatibility only.
124
+ #
125
+ # @return [Numeric]
126
+ #
127
+ # @example
128
+ # bank = Money::Bank::VariableExchange.new
129
+ # bank.set_rate("USD", "CAD", 1.24515)
130
+ # bank.set_rate("CAD", "USD", 0.803115)
131
+ def set_rate: ((Money::Currency | string | Symbol) from, (Money::Currency | string | Symbol) to, Numeric rate, ?::Hash[untyped, untyped] opts) -> Numeric
132
+
133
+ # Retrieve the rate for the given currencies.
134
+ # data access.
135
+ # Delegates to +Money::RatesStore::Memory+
136
+ #
137
+ # @param [Currency, String, Symbol] from Currency to exchange from.
138
+ # @param [Currency, String, Symbol] to Currency to exchange to.
139
+ # @param [Hash] opts Options hash to set special parameters. Backwards compatibility only.
140
+ #
141
+ # @return [Numeric]
142
+ #
143
+ # @example
144
+ # bank = Money::Bank::VariableExchange.new
145
+ # bank.set_rate("USD", "CAD", 1.24515)
146
+ # bank.set_rate("CAD", "USD", 0.803115)
147
+ #
148
+ # bank.get_rate("USD", "CAD") #=> 1.24515
149
+ # bank.get_rate("CAD", "USD") #=> 0.803115
150
+ def get_rate: ((Money::Currency | string | Symbol) from, (Money::Currency | string | Symbol) to, ?::Hash[untyped, untyped] opts) -> Numeric
151
+
152
+ # Return the known rates as a string in the format specified. If +file+
153
+ # is given will also write the string out to the file specified.
154
+ # Available formats are +:json+, +:ruby+ and +:yaml+.
155
+ #
156
+ # @param [Symbol] format Request format for the resulting string.
157
+ # @param [String] file Optional file location to write the rates to.
158
+ # @param [Hash] opts Options hash to set special parameters. Backwards compatibility only.
159
+ #
160
+ # @return [String]
161
+ #
162
+ # @raise +Money::Bank::UnknownRateFormat+ if format is unknown.
163
+ #
164
+ # @example
165
+ # bank = Money::Bank::VariableExchange.new
166
+ # bank.set_rate("USD", "CAD", 1.24515)
167
+ # bank.set_rate("CAD", "USD", 0.803115)
168
+ #
169
+ # s = bank.export_rates(:json)
170
+ # s #=> "{\"USD_TO_CAD\":1.24515,\"CAD_TO_USD\":0.803115}"
171
+ def export_rates: (Symbol format, ?string? file, ?::Hash[untyped, untyped] opts) -> string
172
+
173
+ # This should be deprecated.
174
+ def rates: () -> untyped
175
+
176
+ # Loads rates provided in +string+ given the specified format. Available
177
+ # formats are +:json+, +:ruby+ and +:yaml+.
178
+ # Delegates to +Money::RatesStore::Memory+
179
+ #
180
+ # @param [Symbol] format The format of +string+.
181
+ # @param [String] string The rates string.
182
+ # @param [Hash] opts Options hash to set special parameters. Backwards compatibility only.
183
+ #
184
+ # @return [self]
185
+ #
186
+ # @raise +Money::Bank::UnknownRateFormat+ if format is unknown.
187
+ #
188
+ # @example
189
+ # string = "{\"USD_TO_CAD\":1.24515,\"CAD_TO_USD\":0.803115}"
190
+ # bank = Money::Bank::VariableExchange.new
191
+ # bank.import_rates(:json, string)
192
+ #
193
+ # bank.get_rate("USD", "CAD") #=> 1.24515
194
+ # bank.get_rate("CAD", "USD") #=> 0.803115
195
+ def import_rates: (Symbol format, string string, ?::Hash[untyped, untyped] opts) -> Money::Bank::VariableExchange
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,8 @@
1
+ class Money
2
+ class Currency
3
+ # DEPRECATED. Use the money-heuristics gem instead.
4
+ module Heuristics
5
+ def analyze: (untyped _str) -> untyped
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,322 @@
1
+ class Money
2
+ # Represents a specific currency unit.
3
+ #
4
+ # @see https://en.wikipedia.org/wiki/Currency
5
+ # @see https://www.iso.org/iso-4217-currency-codes.html
6
+ class Currency
7
+ include Comparable
8
+
9
+ extend Enumerable[Money::Currency]
10
+
11
+ extend Money::Currency::Heuristics
12
+
13
+ # Thrown when a Currency has been registered without all the attributes
14
+ # which are required for the current action.
15
+ class MissingAttributeError < StandardError
16
+ def initialize: (untyped method, untyped currency, untyped attribute) -> void
17
+ end
18
+
19
+ # Thrown when an unknown currency is requested.
20
+ class UnknownCurrency < ArgumentError
21
+ end
22
+
23
+ # Thrown when a Money object is created without a currency.
24
+ class NoCurrency < ArgumentError
25
+ end
26
+
27
+ def self.new: (untyped id) -> untyped
28
+
29
+ def self._instances: () -> untyped
30
+
31
+ # Lookup a currency with given +id+ an returns a +Currency+ instance on
32
+ # success, +nil+ otherwise.
33
+ #
34
+ # @param [String, Symbol, #to_s] id Used to look into +table+ and
35
+ # retrieve the applicable attributes.
36
+ #
37
+ # @return [Money::Currency]
38
+ #
39
+ # @example
40
+ # Money::Currency.find(:eur) #=> #<Money::Currency id: eur ...>
41
+ # Money::Currency.find(:foo) #=> nil
42
+ def self.find: ((string | Symbol) id) -> Money::Currency
43
+
44
+ # Lookup a currency with given +num+ as an ISO 4217 numeric and returns an
45
+ # +Currency+ instance on success, +nil+ otherwise.
46
+ #
47
+ # @param [#to_s] num used to look into +table+ in +iso_numeric+ and find
48
+ # the right currency id.
49
+ #
50
+ # @return [Money::Currency]
51
+ #
52
+ # @example
53
+ # Money::Currency.find_by_iso_numeric(978) #=> #<Money::Currency id: eur ...>
54
+ # Money::Currency.find_by_iso_numeric(51) #=> #<Money::Currency id: amd ...>
55
+ # Money::Currency.find_by_iso_numeric('001') #=> nil
56
+ def self.find_by_iso_numeric: ((string | Numeric) num) -> Money::Currency
57
+
58
+ # Wraps the object in a +Currency+ unless it's already a +Currency+
59
+ # object.
60
+ #
61
+ # @param [Object] object The object to attempt and wrap as a +Currency+
62
+ # object.
63
+ #
64
+ # @return [Money::Currency]
65
+ #
66
+ # @example
67
+ # c1 = Money::Currency.new(:usd)
68
+ # Money::Currency.wrap(nil) #=> nil
69
+ # Money::Currency.wrap(c1) #=> #<Money::Currency id: usd ...>
70
+ # Money::Currency.wrap("usd") #=> #<Money::Currency id: usd ...>
71
+ def self.wrap: (Object object) -> (nil | Money::Currency)
72
+
73
+ # List of known currencies.
74
+ #
75
+ # == monetary unit
76
+ # The standard unit of value of a currency, as the dollar in the United States or the peso in Mexico.
77
+ # https://www.answers.com/redirectSearch?query=monetary-unit
78
+ # == fractional monetary unit, subunit
79
+ # A monetary unit that is valued at a fraction (usually one hundredth) of the basic monetary unit
80
+ # https://www.answers.com/redirectSearch?query=fractional-monetary-unit-subunit
81
+ #
82
+ # See https://en.wikipedia.org/wiki/List_of_circulating_currencies and
83
+ # https://metacpan.org/release/TNGUYEN/Locale-Currency-Format-1.28/view/Format.pm
84
+ def self.table: () -> untyped
85
+
86
+ # List the currencies imported and registered
87
+ # @return [Array]
88
+ #
89
+ # @example
90
+ # Money::Currency.all()
91
+ # [#<Currency ..USD>, 'CAD', 'EUR']...
92
+ def self.all: () -> Array[untyped]
93
+
94
+ # We need a string-based validator before creating an unbounded number of
95
+ # symbols.
96
+ # http://www.randomhacks.net.s3-website-us-east-1.amazonaws.com/2007/01/20/13-ways-of-looking-at-a-ruby-symbol/#11
97
+ # https://github.com/RubyMoney/money/issues/132
98
+ #
99
+ # @return [Set]
100
+ def self.stringified_keys: () -> untyped
101
+
102
+ # Register a new currency
103
+ #
104
+ # @param curr [Hash] information about the currency
105
+ # @option priority [Numeric] a numerical value you can use to sort/group
106
+ # the currency list
107
+ # @option iso_code [String] the international 3-letter code as defined
108
+ # by the ISO 4217 standard
109
+ # @option iso_numeric [Integer] the international 3-digit code as
110
+ # defined by the ISO 4217 standard
111
+ # @option name [String] the currency name
112
+ # @option symbol [String] the currency symbol (UTF-8 encoded)
113
+ # @option subunit [String] the name of the fractional monetary unit
114
+ # @option subunit_to_unit [Numeric] the proportion between the unit and
115
+ # the subunit
116
+ # @option separator [String] character between the whole and fraction
117
+ # amounts
118
+ # @option delimiter [String] character between each thousands place
119
+ def self.register: (Hash[untyped, untyped] curr) -> Money::Currency
120
+
121
+ # Inherit a new currency from existing one
122
+ #
123
+ # @param parent_iso_code [String] the international 3-letter code as defined
124
+ # @param curr [Hash] See {register} method for hash structure
125
+ def self.inherit: (string parent_iso_code, Hash[untyped, untyped] curr) -> untyped
126
+
127
+ # Unregister a currency.
128
+ #
129
+ # @param [Object] curr A Hash with the key `:iso_code`, or the ISO code
130
+ # as a String or Symbol.
131
+ #
132
+ # @return [Boolean] true if the currency previously existed, false
133
+ # if it didn't.
134
+ def self.unregister: (Hash[untyped, untyped] curr) -> bool
135
+
136
+ def self.each: () { (untyped) -> untyped } -> untyped
137
+
138
+ def self.reset!: () -> untyped
139
+
140
+ private
141
+
142
+ def self.stringify_keys: () -> untyped
143
+
144
+ public
145
+
146
+ attr_reader id: untyped
147
+
148
+ attr_reader priority: untyped
149
+
150
+ attr_reader iso_code: untyped
151
+
152
+ attr_reader iso_numeric: untyped
153
+
154
+ attr_reader name: untyped
155
+
156
+ attr_reader symbol: untyped
157
+
158
+ attr_reader disambiguate_symbol: untyped
159
+
160
+ attr_reader html_entity: untyped
161
+
162
+ attr_reader subunit: untyped
163
+
164
+ attr_reader subunit_to_unit: untyped
165
+
166
+ attr_reader decimal_mark: untyped
167
+
168
+ attr_reader thousands_separator: untyped
169
+
170
+ attr_reader symbol_first: untyped
171
+
172
+ attr_reader smallest_denomination: untyped
173
+
174
+ attr_reader format: untyped
175
+
176
+ alias separator decimal_mark
177
+
178
+ alias delimiter thousands_separator
179
+
180
+ alias eql? ==
181
+
182
+ # Create a new +Currency+ object.
183
+ #
184
+ # @param [String, Symbol, #to_s] id Used to look into +table+ and retrieve
185
+ # the applicable attributes.
186
+ #
187
+ # @return [Money::Currency]
188
+ #
189
+ # @example
190
+ # Money::Currency.new(:usd) #=> #<Money::Currency id: usd ...>
191
+ def initialize: (untyped id) -> void
192
+
193
+ # Compares +self+ with +other_currency+ against the value of +priority+
194
+ # attribute.
195
+ #
196
+ # @param [Money::Currency] other_currency The currency to compare to.
197
+ #
198
+ # @return [-1,0,1] -1 if less than, 0 is equal to, 1 if greater than
199
+ #
200
+ # @example
201
+ # c1 = Money::Currency.new(:usd)
202
+ # c2 = Money::Currency.new(:jpy)
203
+ # c1 <=> c2 #=> 1
204
+ # c2 <=> c1 #=> -1
205
+ # c1 <=> c1 #=> 0
206
+ def <=>: (untyped other_currency) -> untyped
207
+
208
+ # Compares +self+ with +other_currency+ and returns +true+ if the are the
209
+ # same or if their +id+ attributes match.
210
+ #
211
+ # @param [Money::Currency] other_currency The currency to compare to.
212
+ #
213
+ # @return [Boolean]
214
+ #
215
+ # @example
216
+ # c1 = Money::Currency.new(:usd)
217
+ # c2 = Money::Currency.new(:jpy)
218
+ # c1 == c1 #=> true
219
+ # c1 == c2 #=> false
220
+ def ==: (Money::Currency? other_currency) -> bool
221
+
222
+ private
223
+
224
+ def compare_ids: (untyped other_currency) -> untyped
225
+
226
+ public
227
+
228
+ # Returns a Integer hash value based on the +id+ attribute in order to use
229
+ # functions like & (intersection), group_by, etc.
230
+ #
231
+ # @return [Integer]
232
+ #
233
+ # @example
234
+ # Money::Currency.new(:usd).hash #=> 428936
235
+ def hash: () -> untyped
236
+
237
+ # Returns a human readable representation.
238
+ #
239
+ # @return [String]
240
+ #
241
+ # @example
242
+ # Money::Currency.new(:usd) #=> #<Currency id: usd ...>
243
+ def inspect: () -> ::String
244
+
245
+ # Returns a string representation corresponding to the upcase +id+
246
+ # attribute.
247
+ #
248
+ # --
249
+ # DEV: id.to_s.upcase corresponds to iso_code but don't use ISO_CODE for consistency.
250
+ #
251
+ # @return [String]
252
+ #
253
+ # @example
254
+ # Money::Currency.new(:usd).to_s #=> "USD"
255
+ # Money::Currency.new(:eur).to_s #=> "EUR"
256
+ def to_s: () -> untyped
257
+
258
+ # Returns a string representation corresponding to the upcase +id+
259
+ # attribute. Useful in cases where only implicit conversions are made.
260
+ #
261
+ # @return [String]
262
+ #
263
+ # @example
264
+ # Money::Currency.new(:usd).to_str #=> "USD"
265
+ # Money::Currency.new(:eur).to_str #=> "EUR"
266
+ def to_str: () -> untyped
267
+
268
+ # Returns a symbol representation corresponding to the upcase +id+
269
+ # attribute.
270
+ #
271
+ # @return [Symbol]
272
+ #
273
+ # @example
274
+ # Money::Currency.new(:usd).to_sym #=> :USD
275
+ # Money::Currency.new(:eur).to_sym #=> :EUR
276
+ def to_sym: () -> untyped
277
+
278
+ # Conversion to +self+.
279
+ #
280
+ # @return [self]
281
+ def to_currency: () -> self
282
+
283
+ # Returns currency symbol or iso code for currencies with no symbol.
284
+ #
285
+ # @return [String]
286
+ def code: () -> untyped
287
+
288
+ def symbol_first?: () -> untyped
289
+
290
+ # Returns if a code currency is ISO.
291
+ #
292
+ # @return [Boolean]
293
+ #
294
+ # @example
295
+ # Money::Currency.new(:usd).iso?
296
+ #
297
+ def iso?: () -> untyped
298
+
299
+ # Returns true if a subunit is cents-based.
300
+ #
301
+ # @return [Boolean]
302
+ #
303
+ # @example
304
+ # Money::Currency.new(:usd).cents_based?
305
+ #
306
+ def cents_based?: () -> bool
307
+
308
+ # Returns the relation between subunit and unit as a base 10 exponent.
309
+ #
310
+ # Note that MGA and MRU are exceptions and are rounded to 1
311
+ # @see https://en.wikipedia.org/wiki/ISO_4217#Active_codes
312
+ #
313
+ # @return [Integer]
314
+ def exponent: () -> untyped
315
+
316
+ alias decimal_places exponent
317
+
318
+ private
319
+
320
+ def initialize_data!: () -> untyped
321
+ end
322
+ end
@@ -0,0 +1,6 @@
1
+ class Money
2
+ module LocaleBackend
3
+ class Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ class Money
2
+ module LocaleBackend
3
+ class NotSupported < StandardError
4
+ end
5
+
6
+ class Unknown < ArgumentError
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class Money
2
+ module LocaleBackend
3
+ class I18n < Base
4
+ KEY_MAP: Hash[Symbol, Symbol]
5
+
6
+ def initialize: () -> void
7
+
8
+ def lookup: (Symbol key, untyped _) -> untyped
9
+ end
10
+ end
11
+ end