nepali_number 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29cc199bf66bc17cf33aae0ff233060083e61ed53ea2a667d7568193bd0f2c8d
4
- data.tar.gz: 6f711a7ba972a0630be4e984892366343c5e6c2baec04e7327030450607b5bab
3
+ metadata.gz: a820051dbeea8f45d3a9f5b8e23b170f3d2339827cbbf94a9a81c0074cb7bf95
4
+ data.tar.gz: 69652253a7c525b58b6f41d67f7663e0193adf1083ecf36fcdb4b51ce9584a19
5
5
  SHA512:
6
- metadata.gz: 723097d571768a73e7c4c25b2a973b825da7f82cef4a8caabb7c88e6d83b222d183ac654fb17baabcdaec9aa893688955ef86626d55cb77ed0661e13a7d9c152
7
- data.tar.gz: 5ea57a0185510aa74423cf9648262abf949cd57f5c314055abf4089ce93a190f49c61dfc04230c3c9078be26076536fe88bd6696869cec82534fdd1da3acb8d1
6
+ metadata.gz: 4c6b68ff373bfef520a3bbe2d9f6a88ddad7b910d203a775dac8d39d5b245e3c6d67636a28d4b9eb1494f8d0ec9d4ee3c57614fff70ed2434de74fdf80c4b357
7
+ data.tar.gz: 86c53d7f1287b9b6ae95c21ce6a1e262f3e6b45dfbb344c2e60a46375fdcfb73fbb1f21acc6e60bc98370bd1e5110a7d51984926cff2252d47f5ed597282ff8f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.2.0] - 2026-10-05
2
+
3
+ - Fix whole `BigDecimal` values rendering with a phantom decimal place. `BigDecimal#to_s("F")` always emits at least one digit after the point, so `NepaliNumber.format(BigDecimal("10"))` returned `"10.0"` and `BigDecimal("100.00")` returned `"100.0"`. Whole values now render as whole numbers: `"10"`, `"1,00,000"`. This also reaches `NepaliNumber.currency`, where whole money previously gained a `.0`.
4
+ - A value that genuinely carries a fraction is unchanged (`BigDecimal("10.5")` still formats as `"10.5"`). Truncating or rounding a fraction stays the caller's decision; the formatter no longer invents one.
5
+
6
+ ## [0.1.1] - 2026-09-06
7
+
8
+ - Change default currency symbol from `रु.` to `रु` and remove the default space, so `NepaliNumber.currency(100)` now returns `रु100` (matching `रु1.45` style per Wikipedia/NPR convention).
9
+
1
10
  ## [0.1.0] - 2026-05-27
2
11
 
3
12
  - Merge the richer Devanagari/Nepali-number implementation into `nepali_number`.
data/README.md CHANGED
@@ -22,14 +22,26 @@ NepaliNumber.format("123456.78")
22
22
  # => "1,23,456.78"
23
23
  ```
24
24
 
25
+ A `BigDecimal` with no fractional part formats as a whole number, whatever scale
26
+ its literal carried. One that genuinely has a fraction keeps it, so rounding or
27
+ truncating stays the caller's decision rather than the formatter's.
28
+
29
+ ```ruby
30
+ NepaliNumber.format(BigDecimal("100.0000"))
31
+ # => "100"
32
+
33
+ NepaliNumber.format(BigDecimal("10.5"))
34
+ # => "10.5"
35
+ ```
36
+
25
37
  ### Currency
26
38
 
27
39
  ```ruby
28
40
  NepaliNumber.currency(100)
29
- # => "रु. 100"
41
+ # => "रु100"
30
42
 
31
43
  NepaliNumber.currency(1234567.89, nepali: true)
32
- # => "रु. १२,३४,५६७.८९"
44
+ # => "रु१२,३४,५६७.८९"
33
45
  ```
34
46
 
35
47
  ### Digit conversion
@@ -63,9 +75,49 @@ When Rails is loaded, NepaliNumber adds explicit helpers:
63
75
 
64
76
  ## Development
65
77
 
66
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
78
+ After checking out the repo, run `bin/setup` (or `bundle install`) to install dependencies. You can also run `bin/console` for an interactive prompt.
79
+
80
+ ### Running tests
81
+
82
+ ```sh
83
+ bundle install
84
+ bundle exec rake test # Minitest (test/test_nepali_number.rb)
85
+ bundle exec rake standard # lint (Standard Ruby)
86
+ bundle exec rake # runs test + standard
87
+ ```
88
+
89
+ ### Publishing to RubyGems
90
+
91
+ This repo uses custom release tasks (`Rakefile:19`) — `bundler/gem_tasks` release is not used.
92
+
93
+ ```sh
94
+ # 0. Ensure a clean working tree
95
+ git status --porcelain # must be empty
96
+
97
+ # 1. Bump version in lib/nepali_number/version.rb:4
98
+ bundle exec rake release:bump[patch] # or [minor], [major], or [0.2.0]
99
+ # 2. Update CHANGELOG.md and commit
100
+ git add lib/nepali_number/version.rb CHANGELOG.md
101
+ git commit -m "Bump version to X.Y.Z"
102
+
103
+ # 3. Verify, build, and print publish commands
104
+ bundle exec rake release:prepare # runs release:check_clean, test, standard, build
105
+ # -> builds pkg/nepali_number-X.Y.Z.gem (pkg/ is gitignored)
106
+
107
+ # 4. Push to RubyGems (MFA OTP required)
108
+ bundle exec gem push pkg/nepali_number-X.Y.Z.gem --otp <6-digit-code>
109
+ # gem push uses credentials in ~/.local/share/gem/credentials (see `gem env`)
110
+
111
+ # 5. Tag and push tag
112
+ git tag vX.Y.Z
113
+ git push origin vX.Y.Z
114
+ ```
115
+
116
+ Tips:
67
117
 
68
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
+ - `bundle exec rake release:build` — build only.
119
+ - `bundle exec rake release:commands` — print artifact path and `gem push` / `git tag` commands without running checks.
120
+ - To install locally without publishing: `bundle exec rake install`.
69
121
 
70
122
  ## Contributing
71
123
 
data/Rakefile CHANGED
@@ -1,10 +1,91 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "fileutils"
4
5
  require "minitest/test_task"
6
+ require_relative "lib/nepali_number/version"
5
7
 
6
8
  Minitest::TestTask.create
7
9
 
8
10
  require "standard/rake"
9
11
 
10
12
  task default: %i[test standard]
13
+
14
+ release_gem_name = "nepali_number"
15
+ release_gemspec = "#{release_gem_name}.gemspec"
16
+ release_version = NepaliNumber::VERSION
17
+ release_gem_file = "pkg/#{release_gem_name}-#{release_version}.gem"
18
+
19
+ namespace :release do
20
+ desc "Bump version. Usage: rake release:bump[patch|minor|major|0.2.0]"
21
+ task :bump, [:level_or_version] do |_, args|
22
+ current_version = Gem::Version.new(NepaliNumber::VERSION)
23
+ next_version = next_release_version(current_version, args[:level_or_version])
24
+ version_file = "lib/nepali_number/version.rb"
25
+ contents = File.read(version_file)
26
+ updated = contents.sub(/VERSION = "[^"]+"/, %(VERSION = "#{next_version}"))
27
+
28
+ abort "Could not find VERSION assignment in #{version_file}" if contents == updated
29
+
30
+ File.write(version_file, updated)
31
+ puts "Bumped #{release_gem_name} from #{current_version} to #{next_version}"
32
+ end
33
+
34
+ desc "Verify the working tree has no uncommitted changes"
35
+ task :check_clean do
36
+ status = `git status --porcelain`.strip
37
+ abort "Working tree is not clean:\n#{status}" unless status.empty?
38
+ end
39
+
40
+ desc "Build #{release_gem_name} #{release_version} into pkg/"
41
+ task :build do
42
+ FileUtils.mkdir_p("pkg")
43
+ FileUtils.rm_f(release_gem_file)
44
+ sh "gem build #{release_gemspec} --output #{release_gem_file}"
45
+ end
46
+
47
+ desc "Print the manual commands for publishing #{release_gem_name} #{release_version}"
48
+ task :commands do
49
+ puts
50
+ puts "Release artifact: #{release_gem_file}"
51
+ puts
52
+ puts "Publish:"
53
+ puts " gem push #{release_gem_file}"
54
+ puts
55
+ puts "Tag:"
56
+ puts " git tag v#{release_version}"
57
+ puts " git push origin v#{release_version}"
58
+ puts
59
+ end
60
+
61
+ desc "Run checks, build the gem, and print publish commands"
62
+ task prepare: [:check_clean, :test, :standard, :build, :commands]
63
+ end
64
+
65
+ def next_release_version(current_version, level_or_version)
66
+ level_or_version ||= "patch"
67
+
68
+ case level_or_version
69
+ when "patch", "minor", "major"
70
+ bump_version(current_version, level_or_version)
71
+ when /\A\d+\.\d+\.\d+(?:\.[A-Za-z0-9.-]+)?\z/
72
+ Gem::Version.new(level_or_version)
73
+ else
74
+ abort "Unknown version bump '#{level_or_version}'. Use patch, minor, major, or an explicit version like 0.2.0."
75
+ end
76
+ end
77
+
78
+ def bump_version(version, level)
79
+ segments = version.segments.first(3)
80
+ segments << 0 while segments.length < 3
81
+ major, minor, patch = segments
82
+
83
+ case level
84
+ when "major"
85
+ Gem::Version.new("#{major + 1}.0.0")
86
+ when "minor"
87
+ Gem::Version.new("#{major}.#{minor + 1}.0")
88
+ when "patch"
89
+ Gem::Version.new("#{major}.#{minor}.#{patch + 1}")
90
+ end
91
+ end
@@ -3,7 +3,7 @@
3
3
  module NepaliNumber
4
4
  class Currency
5
5
  class << self
6
- def format(amount, symbol: "रु.", nepali: false, devanagari: nil, delimiter: ",", separator: ".", space: true)
6
+ def format(amount, symbol: "रु", nepali: false, devanagari: nil, delimiter: ",", separator: ".", space: false)
7
7
  formatted = Formatter.format(amount, delimiter: delimiter, separator: separator)
8
8
  return nil if formatted.nil?
9
9
 
@@ -23,12 +23,28 @@ module NepaliNumber
23
23
 
24
24
  private
25
25
 
26
+ # BigDecimal#to_s("F") always emits at least one decimal place, so a value
27
+ # carrying no fraction at all -- BigDecimal("10") -- came out as "10.0". That
28
+ # is an artifact of the rendering, not the number: it made whole share
29
+ # quantities read as fractional, and it did the same to whole money.
30
+ #
31
+ # A value that does carry a fraction keeps it. Callers that need a fraction
32
+ # rounded or dropped decide that themselves; the formatter's job is to not
33
+ # invent one.
26
34
  def normalize(number)
27
- return number.to_s("F") if number.is_a?(BigDecimal)
35
+ return normalize_bigdecimal(number) if number.is_a?(BigDecimal)
28
36
 
29
37
  number.to_s.delete(",")
30
38
  end
31
39
 
40
+ def normalize_bigdecimal(number)
41
+ return number.to_i.to_s if number.frac.zero?
42
+
43
+ # to_s("F") keeps the full precision here, which is the point -- only the
44
+ # trailing ".0" of a whole value was ever wrong.
45
+ number.to_s("F")
46
+ end
47
+
32
48
  def group_integer(integer, delimiter)
33
49
  return integer if integer.length <= 3
34
50
 
@@ -31,7 +31,7 @@ module NepaliNumber
31
31
  Money::Currency.register(
32
32
  iso_code: "NPR",
33
33
  name: "Nepalese Rupee",
34
- symbol: "रु.",
34
+ symbol: "रु",
35
35
  subunit: "Paisa",
36
36
  subunit_to_unit: 100
37
37
  )
@@ -49,7 +49,7 @@ module NepaliNumber
49
49
  end
50
50
 
51
51
  def default_symbol_for(currency)
52
- return "रु." if currency.iso_code == "NPR"
52
+ return "रु" if currency.iso_code == "NPR"
53
53
 
54
54
  currency.symbol || currency.iso_code
55
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NepaliNumber
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nepali_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saroj Maharjan (zoras)
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 4.0.12
72
+ rubygems_version: 4.0.22
73
73
  specification_version: 4
74
74
  summary: Nepali number formatting, humanization, digit conversion, and currency helpers.
75
75
  test_files: []