Module: HumanNumber::NumberSystem
- Defined in:
- lib/human_number/number_system.rb,
lib/human_number/number_system.rb
Overview
Number system determination and formatting for international standards compliance.
This module provides the core logic for determining which number formatting system to use based on locale or currency context. It supports three distinct number systems that align with different cultural and linguistic number naming conventions:
- Default System (Western): thousand, million, billion, trillion (K/M/B/T)
- East Asian System: ten thousand (만/万), hundred million (억/億), trillion (조/兆)
- Indian System: thousand, lakh, crore
The module automatically maps locales and currencies to their culturally appropriate number system, ensuring that formatted numbers follow the conventions expected by users in different regions.
Defined Under Namespace
Classes: DefaultSystem, EastAsianSystem, IndianSystem
Constant Summary collapse
- CURRENCY_SYSTEM_MAPPING =
Currency-to-number-system mapping for culturally appropriate formatting.
Maps ISO 4217 currency codes to their regionally appropriate number formatting systems. Currencies not listed default to the Western system.
{ east_asian: %w[KRW JPY CNY SGD HKD].freeze, indian: %w[INR].freeze, # All other currencies use the default system (K/M/B/T) }.freeze
- LOCALE_SYSTEM_MAPPING =
Locale-to-number-system mapping for linguistic and cultural consistency.
Maps locale identifiers to their culturally appropriate number formatting systems, considering how speakers of each language conceptualize and express large numbers. Locales not listed default to the Western system.
{ east_asian: %i[ko ja zh zh-CN zh-TW].freeze, indian: %i[hi ur bn en-IN].freeze, # All other locales use the default system (K/M/B/T) }.freeze
Class Method Summary collapse
-
.currency_number_system(currency_code:) ⇒ Symbol
Determines the appropriate number system for a given currency code.
-
.number_system(locale: I18n.locale) ⇒ Symbol
Determines the appropriate number system for a given locale.
Class Method Details
.currency_number_system(currency_code:) ⇒ Symbol
Determines the appropriate number system for a given currency code.
This method maps ISO 4217 currency codes to their culturally and geographically appropriate number formatting systems. It considers the regional context where the currency is primarily used and the number formatting conventions of those regions.
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/human_number/number_system.rb', line 163 def currency_number_system(currency_code:) return :default unless currency_code currency_code = currency_code.upcase.strip CURRENCY_SYSTEM_MAPPING.each do |system, currencies| return system if currencies.include?(currency_code) end :default end |
.number_system(locale: I18n.locale) ⇒ Symbol
Determines the appropriate number system for a given locale.
This method maps locale codes to their culturally appropriate number formatting system. It considers regional numbering conventions and linguistic patterns to select the most suitable system.
111 112 113 114 115 116 117 118 119 |
# File 'lib/human_number/number_system.rb', line 111 def number_system(locale: I18n.locale) locale = (locale || I18n.locale).to_sym LOCALE_SYSTEM_MAPPING.each do |system, locales| return system if locales.include?(locale) end :default end |