human_number 0.1.3 → 0.1.5

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: a9d2eb9cac5e189aec1c4c4ad86e0c3a248f466bac8a1af782fc53ff918a43a9
4
- data.tar.gz: f5e4e6a026ff264ab89583cbef216cdbdf872d967ad7b74859b7cd011c5f7373
3
+ metadata.gz: 2dd3c82fa866e72f3077c07772ab73d4eff84d48507e763a0d83708d8204803e
4
+ data.tar.gz: 164c8b2890482b306b2bd0054eedb4aad378bbfa57b0653931535b06ff7b95e6
5
5
  SHA512:
6
- metadata.gz: 32ada67f4efa6c18d358a327c18a913b7b18945db2f70f1ca35de0230250f089885e85425cb40547dfeb4aa16a4c0ddd5eb35ea8b65fb5b27919fb2dd5516e8b
7
- data.tar.gz: d549da397b45f84dff15e15851ef54d1dfb241462ab041d1c0b384dc9ec5811eb744f0c54c28e7dd10087ceeade9b39346708b28cef5d4d09d0fb9e0594b97d8
6
+ metadata.gz: 2629ec3485c1e040a704447dce110df8327a0b27111e688340601b6bffdfcd34efc17c24f2bbe549fe7b3c238542636f0fca775ce6569bae21b31a7c84d31f51
7
+ data.tar.gz: 825db4efc41b062f7dc8604bc74eb91496e172b2d18acd463a9c3c33895328b5d550163d4166b65b938186bd77788b5297ed77e84922f5fa766ae57cb59a4239
data/.rubocop.yml CHANGED
@@ -59,9 +59,3 @@ Metrics/MethodLength:
59
59
 
60
60
  Metrics/ParameterLists:
61
61
  Max: 6
62
-
63
- # Gemspec
64
- Gemspec/RequireMFA:
65
- Enabled: false
66
-
67
- # RSpec rules removed - using basic RuboCop only
data/CHANGELOG.md CHANGED
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  - **Human-readable number formatting** with intelligent, culturally-appropriate abbreviations
14
14
  - **Three cultural number systems** automatically selected by locale:
15
15
  - **Western System**: K/M/B/T (thousand/million/billion/trillion) for English, German, French, Spanish, Italian, Portuguese, Russian, Dutch, Swedish, Danish, Norwegian
16
- - **East Asian System**: 천/만/억/조 (Korean) and 千/万/億/兆 (Japanese/Chinese) for ko, ja, zh, zh-CN, zh-TW locales
16
+ - **East Asian System**: 만/억/조 (Korean) and 万/億/兆 (Japanese/Chinese) for ko, ja, zh, zh-CN, zh-TW locales
17
17
  - **Indian System**: thousand/lakh/crore for Hindi, Urdu, Bengali, and Indian English (hi, ur, bn, en-IN)
18
18
 
19
19
  #### Currency Formatting
data/CLAUDE.md CHANGED
@@ -87,10 +87,10 @@ The gem automatically selects appropriate number systems based on locale:
87
87
  - Used by: English, German, French, Spanish, Italian, Portuguese, Russian, Dutch, Swedish, Danish, Norwegian
88
88
  - Target locales: `%i[en es fr de it pt ru nl sv da no]`
89
89
 
90
- - **East Asian System** (`EastAsianSystem`): 천/만/억/조 or 千/万/億/兆
90
+ - **East Asian System** (`EastAsianSystem`): 만/억/조 or 万/億/兆
91
91
  - Used by: Korean, Japanese, Chinese
92
92
  - Target locales: `%i[ko ja zh zh-CN zh-TW]`
93
- - Units: 천/千 (thousand), 만/万 (ten thousand), 억/億 (hundred million), 조/兆 (trillion)
93
+ - Units: 만/万 (ten thousand), 억/億 (hundred million), 조/兆 (trillion)
94
94
 
95
95
  - **Indian System** (`IndianSystem`): thousand/lakh/crore
96
96
  - Used by: Hindi, Urdu, Bengali, Indian English
@@ -216,4 +216,4 @@ This project is based on the following international standards:
216
216
  - [Microsoft Globalization - Currency Formats](https://learn.microsoft.com/en-us/globalization/locale/currency-formats)
217
217
  - [Unicode CLDR](http://cldr.unicode.org/)
218
218
  - [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)
219
- - [rails-i18n](https://github.com/svenfuchs/rails-i18n)
219
+ - [rails-i18n](https://github.com/svenfuchs/rails-i18n)
data/README.md CHANGED
@@ -5,7 +5,7 @@ HumanNumber is a Ruby gem that implements accurate number formatting based on in
5
5
  ## Features
6
6
 
7
7
  - 🌍 **International Standards Compliance**: Based on Microsoft Globalization and Unicode CLDR standards
8
- - 🔢 **Cultural Number Systems**: Automatic selection of Western (K/M/B/T), East Asian (천/만/억/조), or Indian (lakh/crore) systems
8
+ - 🔢 **Cultural Number Systems**: Automatic selection of Western (K/M/B/T), East Asian (만/억/조), or Indian (lakh/crore) systems
9
9
  - 💰 **Currency Formatting**: ISO 4217 currency codes with native locale precision rules
10
10
  - 🏗️ **Intelligent Abbreviations**: Culturally-appropriate large number simplification
11
11
  - 🔧 **Rails Integration**: Complete compatibility with Rails I18n infrastructure
@@ -160,7 +160,7 @@ HumanNumber.human_number(1_234_567, locale: :ja) #=> "120万"
160
160
  HumanNumber.human_number(100_000_000, locale: :ko) #=> "1억"
161
161
  ```
162
162
 
163
- **Units:** 천/千 (thousand), 만/万 (ten thousand), 억/億 (hundred million), 조/兆 (trillion)
163
+ **Units:** 만/万 (ten thousand), 억/億 (hundred million), 조/兆 (trillion)
164
164
 
165
165
  ### Indian System (lakh/crore)
166
166
  **Used by:** Hindi (hi), Urdu (ur), Bengali (bn), Indian English (en-IN)
data/human_number.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata["homepage_uri"] = spec.homepage
22
22
  spec.metadata["source_code_uri"] = "https://github.com/ether-moon/human_number"
23
23
  spec.metadata["changelog_uri"] = "https://github.com/ether-moon/human_number/blob/main/CHANGELOG.md"
24
+ spec.metadata["rubygems_mfa_required"] = "true"
24
25
 
25
26
  # Specify which files should be added to the gem when it is released.
26
27
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -20,11 +20,8 @@ module HumanNumber
20
20
  def format(formatted_number, currency_code:, locale:)
21
21
  locale = locale.to_sym
22
22
 
23
- # Use shared locale logic to determine display locale
24
- display_locale = HumanNumber::LocaleSupport.primary_locale_for_currency(currency_code, locale)
25
-
26
- # Apply currency formatting to the already formatted number
27
- apply_currency_formatting(formatted_number, currency_code, display_locale)
23
+ # Apply currency formatting using user's locale to determine native vs non-native display
24
+ apply_currency_formatting(formatted_number, currency_code, locale)
28
25
  end
29
26
 
30
27
  private
@@ -200,10 +200,18 @@ module HumanNumber
200
200
 
201
201
  # Format unit parts for abbreviated display (e.g., "1.2M")
202
202
  def format_abbreviated_unit_parts(breakdown, locale, abbr_units, max_digits, trim_zeros)
203
+ # Check if we're in human formatting mode (any non-:units parts exist)
204
+ human_formatting_applied = breakdown.any? { |unit_info| unit_info[:unit_key] != :units }
205
+
203
206
  breakdown.map do |unit_info|
204
207
  if unit_info[:unit_key] == :units
205
- # Raw numbers don't need significant digits rounding
206
- format_raw_number_count(unit_info[:count], max_digits, trim_zeros)
208
+ if human_formatting_applied
209
+ # Part of human formatting - no delimiters
210
+ unit_info[:count].to_s
211
+ else
212
+ # Numbers below minimum unit threshold - apply locale formatting
213
+ Number.format_below_min_unit(unit_info[:count], locale)
214
+ end
207
215
  else
208
216
  # Format with unit symbol (e.g., "1.2" + "M" = "1.2M")
209
217
  format_number_with_unit_symbol(unit_info, locale, abbr_units, max_digits, trim_zeros)
@@ -373,10 +381,18 @@ module HumanNumber
373
381
 
374
382
  # Format unit parts for complete display (e.g., "1M 234K 567")
375
383
  def format_all_unit_parts(breakdown, locale, abbr_units)
384
+ # Check if we're in human formatting mode (any non-:units parts exist)
385
+ human_formatting_applied = breakdown.any? { |unit_info| unit_info[:unit_key] != :units }
386
+
376
387
  breakdown.map do |unit_info|
377
388
  if unit_info[:unit_key] == :units
378
- # Raw numbers shown as integers in complete mode
379
- unit_info[:count].to_i.to_s
389
+ if human_formatting_applied
390
+ # Part of human formatting - no delimiters
391
+ unit_info[:count].to_i.to_s
392
+ else
393
+ # Numbers below minimum unit threshold - apply locale formatting
394
+ Number.format_below_min_unit(unit_info[:count].to_i, locale)
395
+ end
380
396
  else
381
397
  # Format each unit part with its symbol
382
398
  format_complete_unit_with_symbol(unit_info, locale, abbr_units)
@@ -400,7 +416,6 @@ module HumanNumber
400
416
  { key: :trillion, divisor: 1_000_000_000_000 },
401
417
  { key: :hundred_million, divisor: 100_000_000 },
402
418
  { key: :ten_thousand, divisor: 10_000 },
403
- { key: :thousand, divisor: 1_000 },
404
419
  ].freeze
405
420
 
406
421
  class << self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HumanNumber
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/human_number.rb CHANGED
@@ -26,7 +26,7 @@ module HumanNumber
26
26
  # This method provides culturally-appropriate number formatting with automatic
27
27
  # unit system selection based on locale:
28
28
  # - **Western locales**: K/M/B/T (thousand/million/billion/trillion)
29
- # - **East Asian locales**: 천/만/억/조 or 千/万/億/兆
29
+ # - **East Asian locales**: 만/억/조 or 万/億/兆
30
30
  # - **Indian locales**: thousand/lakh/crore
31
31
  #
32
32
  # @param number [Numeric] The number to format
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.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ether Moon
@@ -108,6 +108,7 @@ metadata:
108
108
  homepage_uri: https://github.com/ether-moon/human_number
109
109
  source_code_uri: https://github.com/ether-moon/human_number
110
110
  changelog_uri: https://github.com/ether-moon/human_number/blob/main/CHANGELOG.md
111
+ rubygems_mfa_required: 'true'
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib