human_number 0.1.10 → 0.2.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 +4 -4
- data/CHANGELOG.md +34 -99
- data/README.md +97 -4
- data/lib/human_number/formatters/number.rb +10 -397
- data/lib/human_number/number_system.rb +657 -0
- data/lib/human_number/version.rb +1 -1
- data/lib/human_number.rb +65 -0
- metadata +2 -1
data/lib/human_number.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "human_number/version"
|
|
8
8
|
require_relative "human_number/locale_support"
|
9
9
|
require_relative "human_number/formatters/number"
|
10
10
|
require_relative "human_number/formatters/currency"
|
11
|
+
require_relative "human_number/number_system"
|
11
12
|
|
12
13
|
module HumanNumber
|
13
14
|
class Error < StandardError; end
|
@@ -179,6 +180,70 @@ module HumanNumber
|
|
179
180
|
Formatters::Currency.format(formatted_number, currency_code:, locale:)
|
180
181
|
end
|
181
182
|
|
183
|
+
# Determines the number system used for a given locale.
|
184
|
+
#
|
185
|
+
# This method identifies which cultural number system (Western, East Asian, or Indian)
|
186
|
+
# is used for formatting numbers in the specified locale.
|
187
|
+
#
|
188
|
+
# @param locale [Symbol, String] The locale for system determination (default: current I18n locale)
|
189
|
+
# Determines which cultural number system to use for formatting
|
190
|
+
#
|
191
|
+
# @return [Symbol] The number system identifier
|
192
|
+
# - `:default` - Western system (K/M/B/T for thousand/million/billion/trillion)
|
193
|
+
# - `:east_asian` - East Asian system (만/억/조 or 万/億/兆)
|
194
|
+
# - `:indian` - Indian subcontinent system (thousand/lakh/crore)
|
195
|
+
#
|
196
|
+
# @example Basic usage
|
197
|
+
# HumanNumber.number_system(locale: :en) #=> :default
|
198
|
+
# HumanNumber.number_system(locale: :ko) #=> :east_asian
|
199
|
+
# HumanNumber.number_system(locale: :hi) #=> :indian
|
200
|
+
#
|
201
|
+
# @example Cultural system examples
|
202
|
+
# HumanNumber.number_system(locale: :ja) #=> :east_asian (Japanese: 万/億/兆)
|
203
|
+
# HumanNumber.number_system(locale: :"zh-CN") #=> :east_asian (Chinese: 万/億/兆)
|
204
|
+
# HumanNumber.number_system(locale: :"en-IN") #=> :indian (Indian English: lakh/crore)
|
205
|
+
#
|
206
|
+
# @see NumberSystem.number_system The underlying implementation
|
207
|
+
def number_system(locale: I18n.locale)
|
208
|
+
validate_locale!(locale)
|
209
|
+
NumberSystem.number_system(locale:)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Determines the number system used for a given currency.
|
213
|
+
#
|
214
|
+
# This method identifies which cultural number system is typically used
|
215
|
+
# when formatting amounts in the specified currency, based on the currency's
|
216
|
+
# primary cultural and linguistic context.
|
217
|
+
#
|
218
|
+
# @param currency_code [String] ISO 4217 currency code (e.g., 'USD', 'KRW', 'INR')
|
219
|
+
# The currency code to determine the number system for
|
220
|
+
#
|
221
|
+
# @return [Symbol] The number system identifier
|
222
|
+
# - `:default` - Western system (K/M/B/T for thousand/million/billion/trillion)
|
223
|
+
# - `:east_asian` - East Asian system (만/억/조 or 万/億/兆)
|
224
|
+
# - `:indian` - Indian subcontinent system (thousand/lakh/crore)
|
225
|
+
#
|
226
|
+
# @example Basic usage
|
227
|
+
# HumanNumber.currency_number_system(currency_code: 'USD') #=> :default
|
228
|
+
# HumanNumber.currency_number_system(currency_code: 'KRW') #=> :east_asian
|
229
|
+
# HumanNumber.currency_number_system(currency_code: 'INR') #=> :indian
|
230
|
+
#
|
231
|
+
# @example East Asian currencies
|
232
|
+
# HumanNumber.currency_number_system(currency_code: 'JPY') #=> :east_asian
|
233
|
+
# HumanNumber.currency_number_system(currency_code: 'CNY') #=> :east_asian
|
234
|
+
# HumanNumber.currency_number_system(currency_code: 'HKD') #=> :east_asian
|
235
|
+
#
|
236
|
+
# @example Default system currencies
|
237
|
+
# HumanNumber.currency_number_system(currency_code: 'EUR') #=> :default
|
238
|
+
# HumanNumber.currency_number_system(currency_code: 'GBP') #=> :default
|
239
|
+
# HumanNumber.currency_number_system(currency_code: 'CAD') #=> :default
|
240
|
+
#
|
241
|
+
# @see NumberSystem.currency_number_system The underlying implementation
|
242
|
+
def currency_number_system(currency_code:)
|
243
|
+
validate_currency_code!(currency_code)
|
244
|
+
NumberSystem.currency_number_system(currency_code:)
|
245
|
+
end
|
246
|
+
|
182
247
|
private
|
183
248
|
|
184
249
|
# Input validation methods - minimal validation for stability
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ether Moon
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/human_number/formatters/currency.rb
|
83
83
|
- lib/human_number/formatters/number.rb
|
84
84
|
- lib/human_number/locale_support.rb
|
85
|
+
- lib/human_number/number_system.rb
|
85
86
|
- lib/human_number/rails/helpers.rb
|
86
87
|
- lib/human_number/railtie.rb
|
87
88
|
- lib/human_number/version.rb
|