human_number 0.1.10 → 0.2.1

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: 25a997b6244948ebded5aa57455a54c930b8ea0f6255e17f620a315e578d0b58
4
- data.tar.gz: 5ee0a391c1875a6cde5843535949a7995d87ccbc179ffd7734f315e0292f5c98
3
+ metadata.gz: 640f25eea39d66d28a79be7612896b88052b090e80ec704f7d0ae7a0fd93a8a7
4
+ data.tar.gz: 3d328389e35e2e5c199029557ecbe7b7df2ec1aa3727edf712e5b0b540c001c3
5
5
  SHA512:
6
- metadata.gz: d566ce576fbf747a5db5263a4ed8fbe84e20ea11d96d51da4217e80ba9c0046eaa1f4e5b4a0e87494be49444e57ed1f5823354050a28edae15c25403ffbc889a
7
- data.tar.gz: 0e2e0b57bba47bcd184990bd3988b4121abc8297246bd8f8a21fb53c32dbb17a3d39d2547c0dd4f7ea202c543265878698e39b918f4e84c1b2465a98089e1bb5
6
+ metadata.gz: 2c42af2e46c77bd2258cd2b6a5a26520022f394d27aa5b082c2acca2e21da3ed90e37197194f5df005893757655934a00a7508328aaa9195399bd1b839435610
7
+ data.tar.gz: 6dae26caf8f22d3340ff6115f677402d1a3c2a90ee6eca5dcdbac689010375e5ddbdf4f8b7a3e9bcbdcfa1b645c14f91b7499ba4f78a131f74cfb13f8db6069f
data/CHANGELOG.md CHANGED
@@ -5,122 +5,65 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [0.1.10] - 2025-08-19
8
+ ## [0.2.1] - 2025-08-25
9
+
10
+ ### Fixed
11
+ - `abbr_units: false` displaying fallback `TEN_THOUSAND` instead of proper locale text
12
+ - KRW currency formatting now correctly shows `"123.5만원"` instead of `"150TEN_THOUSAND원"`
13
+ - Added missing `units` sections to locale files for East Asian and Indian systems
14
+
15
+ ## [0.2.0] - 2025-08-25
16
+
17
+ ### Added
18
+ - `HumanNumber.number_system(locale:)` - Detects number system (`:default`, `:east_asian`, `:indian`) by locale
19
+ - `HumanNumber.currency_number_system(currency_code:)` - Detects number system by currency code
20
+ - New `HumanNumber::NumberSystem` module with centralized system logic
9
21
 
10
22
  ### Changed
23
+ - Moved system classes (`DefaultSystem`, `EastAsianSystem`, `IndianSystem`) to `NumberSystem` module
24
+ - Reduced `number.rb` formatter from 475 to 93 lines (80% reduction)
25
+ - Updated I18n test patterns to use `I18n.with_locale` for thread safety
26
+ - Enhanced README with new API documentation and examples
11
27
 
12
- - **BREAKING CHANGE: Default number formatting behavior**: Changed `max_digits` default value from `2` to `nil`
13
- - Numbers now display complete breakdown by default (e.g., `"1M 234K 567"` instead of `"1.2M"`)
14
- - Previous abbreviated behavior still available by explicitly setting `max_digits: 2`
15
- - Affects all methods: `HumanNumber.human_number()`, `HumanNumber.human_currency()`, and Rails helpers
16
- - Provides safer default behavior with no information loss
17
- - Maintains backward compatibility for explicit `max_digits` parameter usage
28
+ ## [0.1.10] - 2025-08-19
29
+
30
+ ### Changed
31
+ - **BREAKING CHANGE**: Changed `max_digits` default from `2` to `nil`
32
+ - Numbers now show complete breakdown by default (`"1M 234K 567"` instead of `"1.2M"`)
33
+ - Previous abbreviated behavior available with explicit `max_digits: 2`
18
34
 
19
35
  ## [0.1.9] - 2025-08-05
20
36
 
21
37
  ### Changed
22
- - **East Asian separator formatting**: Japanese numbers now use culturally appropriate spacing
23
- - Japanese: `'12億3456万7890円'` (no spaces between units)
24
- - Korean/Chinese: `'12억 3456만 7890원'` (spaces maintained as default)
25
- - **Locale-based separator configuration**: Added `number.human.decimal_units.separator` for customizable unit separators
38
+ - Japanese numbers use culturally appropriate spacing (no spaces between units)
39
+ - Korean/Chinese maintain spaces between units as default
40
+ - Added `number.human.decimal_units.separator` for customizable separators
26
41
 
27
42
  ## [0.1.8] - 2025-08-05
28
43
 
29
44
  ### Fixed
30
- - **I18n fallback contamination**: Resolved currency symbol cross-contamination where Korean won symbols (원) appeared for other currencies like CAD due to I18n fallback behavior
31
- - **Translation missing errors**: Fixed missing translation errors for various currency/locale combinations
32
- - **Rails configuration warnings**: Eliminated Rails configuration warnings in test environment
45
+ - I18n fallback currency symbol contamination (Korean won symbols appearing for other currencies)
46
+ - Missing translation errors for various currency/locale combinations
47
+ - Rails configuration warnings in test environment
33
48
 
34
49
  ### Changed
35
- - **Currency native locale mappings**: Corrected CURRENCY_NATIVE_LOCALES to use only accurate locale associations (e.g., CAD now maps to en-CA/fr-CA only, not generic en/fr)
36
- - **Locale file organization**: Moved locale files from `config/locales/` to `lib/locales/` for better gem structure
37
-
38
- ### Improved
39
- - **Rails-i18n integration**: Enhanced loading order and initialization to prevent locale conflicts
40
- - **Test infrastructure**: Updated RSpec mocks and test expectations for better reliability
41
- - **I18n isolation**: Added `fallback: false` parameter to prevent cross-locale pollution
50
+ - Corrected CURRENCY_NATIVE_LOCALES mappings for accuracy
51
+ - Moved locale files from `config/locales/` to `lib/locales/`
42
52
 
43
53
  ## [0.1.0] - 2025-07-31
44
54
 
45
55
  ### Added
46
-
47
- #### Core Number Formatting
48
- - **Human-readable number formatting** with intelligent, culturally-appropriate abbreviations
49
- - **Three cultural number systems** automatically selected by locale:
50
- - **Western System**: K/M/B/T (thousand/million/billion/trillion) for English, German, French, Spanish, Italian, Portuguese, Russian, Dutch, Swedish, Danish, Norwegian
51
- - **East Asian System**: 만/억/조 (Korean) and 万/億/兆 (Japanese/Chinese) for ko, ja, zh, zh-CN, zh-TW locales
52
- - **Indian System**: thousand/lakh/crore for Hindi, Urdu, Bengali, and Indian English (hi, ur, bn, en-IN)
53
-
54
- #### Currency Formatting
55
- - **ISO 4217 currency code support** with native locale precision rules
56
- - **Cross-locale consistency**: USD always shows 2 decimals, JPY shows 0, regardless of display locale
57
- - **40+ currency mappings** with native locale associations for accurate formatting
58
- - **Human-readable currency formatting** combining cultural abbreviations with currency symbols
59
-
60
- #### API Methods
61
- - `HumanNumber.human_number(number, **options)` - Formats numbers with cultural abbreviations
62
- - `HumanNumber.currency(number, currency_code:, locale:)` - Standard currency formatting
63
- - `HumanNumber.human_currency(number, currency_code:, locale:, **options)` - Currency with abbreviations
64
-
65
- #### Formatting Options
66
- - **Precision control**: `max_digits` parameter for significant digit control (1-4 digits or nil for complete mode)
67
- - **Unit preferences**: `abbr_units` to choose between abbreviated (K/M) vs full words (thousand/million)
68
- - **Minimum thresholds**: `min_unit` to prevent abbreviation below specified amounts
69
- - **Zero trimming**: `trim_zeros` to control trailing decimal zero display
70
- - **Complete mode**: `max_digits: nil` shows full breakdown across multiple units (e.g., "1M 234K 567")
71
-
72
- #### Rails Integration
73
- - **Automatic Rails detection** and helper loading via Railtie
74
- - **View helpers**: `human_number`, `currency`, `human_currency` with Rails-friendly parameter handling
75
- - **I18n integration**: Automatic locale detection from `I18n.locale`
76
-
77
- #### Locale Data System
78
- - **Hybrid locale approach**: Combines rails-i18n for base formatting with custom locale files for unit symbols
79
- - **14 custom locale files**: bn, de, en-GB, en-IN, en, es, fr, hi, ja, ko, ur, zh-CN, zh-TW, zh
80
- - **Rails-i18n structure**: `number.human.decimal_units.units` for unit translations
81
- - **Automatic locale file loading** from `config/locales/` directory
82
-
83
- #### Architecture & Performance
84
- - **Configuration-free design**: No global state, explicit parameters for predictable behavior
85
- - **Direct class methods**: Zero object instantiation overhead for optimal performance
86
- - **Thread-safe implementation**: No shared mutable state between calls
87
- - **Two-stage formatting**: Clean separation between number formatting and currency application
88
- - **Efficient I18n**: Leverages Rails I18n caching mechanisms
89
-
90
- #### Standards Compliance
91
- - **Microsoft Globalization documentation** compliance for cultural number formatting
92
- - **Unicode CLDR standards** for locale-specific formatting rules
93
- - **ISO 4217 standard** for currency codes and precision rules
94
- - **rails-i18n integration** for verified locale data
95
-
96
- #### Development Infrastructure
97
- - **Comprehensive test suite**: 106 test examples with 100% code coverage
98
- - **RuboCop compliance**: Complete adherence to Ruby style guidelines
99
- - **Rake tasks**: Integrated testing and linting workflow
100
- - **Gem packaging**: Ready for RubyGems distribution
101
-
102
- #### Dependencies
103
- - **Runtime dependencies**: `actionview` (>= 5.2), `i18n` (>= 1.6, < 2), `rails-i18n` (>= 5.1)
104
- - **Ruby requirement**: >= 3.1.0
105
- - **Development dependencies**: `rspec`, `rubocop`, `simplecov`, `yard`
106
-
107
- ### Technical Details
108
-
109
- #### Number System Architecture
110
- - **DefaultSystem**: Handles Western locales with standard thousand/million/billion/trillion units
111
- - **EastAsianSystem**: Implements East Asian counting with ten-thousand (만/万) and hundred-million (억/億) bases
112
- - **IndianSystem**: Supports Indian numbering with lakh (100,000) and crore (10,000,000) units
113
-
114
- #### Currency Precision System
115
- - **LocaleSupport module**: Centralized currency-to-locale mapping for consistent precision
116
- - **Native locale detection**: Automatic selection of appropriate formatting locale for each currency
117
- - **Precision inheritance**: Currency formatting inherits precision rules from native locales
118
-
119
- #### Formatter Pattern
120
- - **Formatters::Number**: Core number formatting with intelligent unit system selection
121
- - **Formatters::Currency**: Currency symbol and format string application
122
- - **Clean separation**: Number formatting independent of currency concerns
123
-
56
+ - Human-readable number formatting with cultural abbreviations
57
+ - Three number systems: Western (K/M/B/T), East Asian (만/억/조), Indian (lakh/crore)
58
+ - ISO 4217 currency code support with native locale precision
59
+ - API methods: `human_number`, `currency`, `human_currency`
60
+ - Rails integration with automatic helper loading
61
+ - Configuration-free design with explicit parameters
62
+ - 14 custom locale files with rails-i18n integration
63
+ - Thread-safe implementation
64
+
65
+ [0.2.1]: https://github.com/ether-moon/human_number/releases/tag/v0.2.1
66
+ [0.2.0]: https://github.com/ether-moon/human_number/releases/tag/v0.2.0
124
67
  [0.1.10]: https://github.com/ether-moon/human_number/releases/tag/v0.1.10
125
68
  [0.1.9]: https://github.com/ether-moon/human_number/releases/tag/v0.1.9
126
69
  [0.1.8]: https://github.com/ether-moon/human_number/releases/tag/v0.1.8
data/README.md CHANGED
@@ -123,6 +123,76 @@ HumanNumber.human_currency(1_234_567, currency_code: 'USD', locale: :en, max_dig
123
123
  HumanNumber.human_currency(1_234_567, currency_code: 'USD', locale: :en, max_digits: nil) #=> "$1M 234K 567"
124
124
  ```
125
125
 
126
+ ### System Detection Methods
127
+
128
+ #### `HumanNumber.number_system(locale:)`
129
+
130
+ Determines which number system is used for a given locale. Returns a symbol indicating the cultural number formatting system.
131
+
132
+ ```ruby
133
+ # Western/Default system (K/M/B/T)
134
+ HumanNumber.number_system(locale: :en) #=> :default
135
+ HumanNumber.number_system(locale: :fr) #=> :default
136
+ HumanNumber.number_system(locale: :de) #=> :default
137
+
138
+ # East Asian system (만/억/조 or 万/億/兆)
139
+ HumanNumber.number_system(locale: :ko) #=> :east_asian
140
+ HumanNumber.number_system(locale: :ja) #=> :east_asian
141
+ HumanNumber.number_system(locale: :zh) #=> :east_asian
142
+
143
+ # Indian system (thousand/lakh/crore)
144
+ HumanNumber.number_system(locale: :hi) #=> :indian
145
+ HumanNumber.number_system(locale: :'en-IN') #=> :indian
146
+
147
+ # Defaults to current I18n.locale when not specified
148
+ HumanNumber.number_system #=> (uses I18n.locale)
149
+ ```
150
+
151
+ **Return Values:**
152
+ - `:default` - Western system using K/M/B/T (thousand/million/billion/trillion)
153
+ - `:east_asian` - Asian system using 만/억/조 or 万/億/兆 patterns
154
+ - `:indian` - South Asian system using thousand/lakh/crore
155
+
156
+ #### `HumanNumber.currency_number_system(currency_code:)`
157
+
158
+ Determines which number system is used for a given currency code. Returns a symbol indicating the culturally appropriate formatting system for that currency's region.
159
+
160
+ ```ruby
161
+ # Default system currencies
162
+ HumanNumber.currency_number_system(currency_code: 'USD') #=> :default
163
+ HumanNumber.currency_number_system(currency_code: 'EUR') #=> :default
164
+ HumanNumber.currency_number_system(currency_code: 'GBP') #=> :default
165
+
166
+ # East Asian system currencies
167
+ HumanNumber.currency_number_system(currency_code: 'KRW') #=> :east_asian # Korean Won
168
+ HumanNumber.currency_number_system(currency_code: 'JPY') #=> :east_asian # Japanese Yen
169
+ HumanNumber.currency_number_system(currency_code: 'CNY') #=> :east_asian # Chinese Yuan
170
+
171
+ # Indian system currencies
172
+ HumanNumber.currency_number_system(currency_code: 'INR') #=> :indian # Indian Rupee
173
+
174
+ # Case-insensitive and handles whitespace
175
+ HumanNumber.currency_number_system(currency_code: 'krw') #=> :east_asian
176
+ HumanNumber.currency_number_system(currency_code: ' USD ') #=> :default
177
+ ```
178
+
179
+ **Practical Usage:**
180
+ These methods are useful for understanding which formatting system will be applied, or for building custom formatting logic:
181
+
182
+ ```ruby
183
+ # Check system before formatting
184
+ system = HumanNumber.number_system(locale: :ko)
185
+ if system == :east_asian
186
+ puts "Will use 만/억/조 units"
187
+ result = HumanNumber.human_number(50_000, locale: :ko) #=> "5만"
188
+ end
189
+
190
+ # Currency-aware system detection
191
+ currency_system = HumanNumber.currency_number_system(currency_code: 'KRW')
192
+ locale_system = HumanNumber.number_system(locale: :ko)
193
+ puts "Consistent systems!" if currency_system == locale_system #=> true
194
+ ```
195
+
126
196
  ### Rails Integration
127
197
 
128
198
  In Rails applications, helper methods are automatically available:
@@ -300,10 +370,33 @@ $ rake # Runs both spec and rubocop
300
370
 
301
371
  To add support for a new locale:
302
372
 
303
- 1. Add locale to appropriate number system in `lib/human_number/formatters/number.rb`
304
- 2. Create locale file in `config/locales/` with unit translations
305
- 3. Add currency mapping to `CURRENCY_NATIVE_LOCALES` if applicable
306
- 4. Add comprehensive tests
373
+ 1. Add locale to appropriate system mapping in `lib/human_number/number_system.rb`:
374
+ - Update `LOCALE_SYSTEM_MAPPING` to include the new locale
375
+ - If needed, add currency mapping to `CURRENCY_SYSTEM_MAPPING`
376
+ 2. Create locale file in `config/locales/` with unit translations following rails-i18n structure
377
+ 3. Add currency precision mapping to `CURRENCY_NATIVE_LOCALES` in `lib/human_number/locale_support.rb` if applicable
378
+ 4. Add comprehensive tests covering the new locale in both `spec/human_number_spec.rb` and `spec/human_number/number_system_spec.rb`
379
+
380
+ **Example:** Adding Portuguese (Brazil) support:
381
+ ```ruby
382
+ # In lib/human_number/number_system.rb
383
+ LOCALE_SYSTEM_MAPPING = {
384
+ east_asian: %i[ko ja zh zh-CN zh-TW].freeze,
385
+ indian: %i[hi ur bn en-IN].freeze,
386
+ # Add pt-BR to default system (no entry needed)
387
+ }.freeze
388
+
389
+ # In config/locales/pt-BR.yml
390
+ pt-BR:
391
+ number:
392
+ human:
393
+ decimal_units:
394
+ abbr_units:
395
+ thousand: "K"
396
+ million: "M"
397
+ billion: "B"
398
+ trillion: "T"
399
+ ```
307
400
 
308
401
  ## License
309
402