normalize_digits 0.1.0 → 0.1.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: b71f47e65081d82f5024e730b131c9ba7d2b8e969761f0ec542cc5e5d1f4e96b
4
- data.tar.gz: d1e42c7c0c1452c552ca2e8fd8b918bd7e5b41bc6c5ab292651da78601ed2a4e
3
+ metadata.gz: 778e0a62279930e47ef74cd21d2807d4c7cb720dcb0deb6ea7861d4025ebf43e
4
+ data.tar.gz: 8fbf501a76462502277d5dc665cf0aae8748fec28a833bc96d23c66f97de23da
5
5
  SHA512:
6
- metadata.gz: f0f10717beb08f93a12d9c759e2218c5df6df9a381215b0f589af92cdd39e11e52831e312f0beda8a9e0c2bc0a37117dd17a5859a7085989ba740553a73e6de0
7
- data.tar.gz: 907e8a91a39c8224c54484e563045582f4db0dcb36b1303c3fdf3de0d4322892df712cab7d8cfbe63c93c95f71f3d80c2d9cf955107f2d85b78f27c33fae5a8f
6
+ metadata.gz: 9374156d16f29ca671f8341f78f628b8123eda4c8158d6dd1f884e90f9511aa9b6cad616b30cb8666f67655518584c4ed8c7f452a96bd8da78a756dbfa070191
7
+ data.tar.gz: 217be1503fc313bd359a55a5d59c2f204816335c96b10976f9a68b566504eb99314cc676b50a170aad70c21414d984ebfaf825b902f3700ea025edcd0dab8b4d
data/README.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # NormalizeDigits
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/normalize_digits`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/normalize_digits.svg)](https://badge.fury.io/rb/normalize_digits)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ NormalizeDigits is a lightweight ActiveModel extension that automatically converts non-English digits (like Arabic,
6
+ Persian, etc.) to standard English digits (`0-9`) before validation. This is useful for applications where users might
7
+ input localized numerals, and consistent numeric formatting is required.
8
+
9
+ ## Features
10
+
11
+ - Automatically normalizes any non-English digits to ASCII numerals.
12
+ - Integrates seamlessly with ActiveModel or ActiveRecord attributes.
13
+ - Useful for form inputs, APIs, and user-generated content.
6
14
 
7
15
  ## Installation
8
16
 
@@ -14,30 +22,58 @@ gem 'normalize_digits'
14
22
 
15
23
  And then execute:
16
24
 
17
- $ bundle
25
+ ```shell
26
+ bundle install
27
+ ```
18
28
 
19
29
  Or install it yourself as:
20
30
 
21
- $ gem install normalize_digits
31
+ ```shell
32
+ gem install normalize_digits
33
+ ```
22
34
 
23
35
  ## Usage
24
36
 
25
- TODO: Write usage instructions here
37
+ Simply include the concern in your model and specify which attributes you want to normalize:
26
38
 
27
- ## Development
39
+ ```ruby
28
40
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+ class User < ApplicationRecord
42
+ include NormalizeDigits
30
43
 
31
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+ normalize_digits
45
+ # normalize_digits only: [:username]
46
+ # normalize_digits except: [:username]
47
+ end
48
+ ```
32
49
 
33
- ## Contributing
50
+ Before validation, any non-English digits in the specified fields will be converted to standard 0-9.
34
51
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/normalize_digits. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
52
+ ### Example
36
53
 
37
- ## License
54
+ ```ruby
55
+ user = User.new(phone_number: "٠٥٠١٢٣٤٥٦٧")
56
+ user.valid?
57
+ user.phone_number
58
+ # => "0501234567"
59
+ ```
38
60
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+ ### Supported Digit Sets
40
62
 
41
- ## Code of Conduct
63
+ The gem currently supports:
64
+ • Arabic-Indic digits: `٠١٢٣٤٥٦٧٨٩`
65
+ • Eastern Arabic digits: `۰۱۲۳۴۵۶۷۸۹`
66
+ • Can be extended easily via the matchers.
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/your-username/normalize_digits.
71
+ 1. Fork the repo
72
+ 2. Create your feature branch (git checkout -b feature/awesome)
73
+ 3. Commit your changes (git commit -am 'Add awesome feature')
74
+ 4. Push to the branch (git push origin feature/awesome)
75
+ 5. Create a new Pull Request
76
+
77
+ ## License
42
78
 
43
- Everyone interacting in the NormalizeDigits project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/normalize_digits/blob/master/CODE_OF_CONDUCT.md).
79
+ The gem is available as open source under the terms of the MIT License.
@@ -28,7 +28,7 @@ module NormalizeDigits
28
28
 
29
29
  # RSpec 3.x
30
30
  def failure_message
31
- "Expected to be englishized from #{@attribute}, but it was not"
31
+ "Expected to be normalized from #{@attribute}, but it was not"
32
32
  end
33
33
 
34
34
  # RSpec 1.2, 2.x
@@ -36,7 +36,7 @@ module NormalizeDigits
36
36
 
37
37
  # RSpec 3.x
38
38
  def failure_message_when_negated
39
- "Expected to remain on #{@attribute}, but it was englishized"
39
+ "Expected to remain on #{@attribute}, but it was normalized"
40
40
  end
41
41
 
42
42
  # RSpec 1.2, 2.x
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NormalizeDigits
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -68,7 +68,7 @@ RSpec.describe NormalizeDigits do
68
68
  context "Englishize all attrs" do
69
69
  subject { instance_for(EnglishizeAll) }
70
70
 
71
- it "should englishize strings" do
71
+ it "should normalize strings" do
72
72
  is_expected.to normalize_digits_for(:a)
73
73
  is_expected.to normalize_digits_for(:b)
74
74
  is_expected.to normalize_digits_for(:d)
@@ -90,7 +90,7 @@ RSpec.describe NormalizeDigits do
90
90
  context "Englishize only one attr" do
91
91
  subject { instance_for(EnglishizeOnlyOne) }
92
92
 
93
- it "should englishize included strings" do
93
+ it "should normalize included strings" do
94
94
  is_expected.to normalize_digits_for(:a)
95
95
  end
96
96
 
@@ -102,7 +102,7 @@ RSpec.describe NormalizeDigits do
102
102
  context "Englishize only two attrs" do
103
103
  subject { instance_for(EnglishizeOnlyTwo) }
104
104
 
105
- it "should englishize included strings" do
105
+ it "should normalize included strings" do
106
106
  is_expected.to normalize_digits_for(:a)
107
107
  is_expected.to normalize_digits_for(:b)
108
108
  end
@@ -115,7 +115,7 @@ RSpec.describe NormalizeDigits do
115
115
  context "Englishize except one attr" do
116
116
  subject { instance_for(EnglishizeExceptOne) }
117
117
 
118
- it "should englishize included strings" do
118
+ it "should normalize included strings" do
119
119
  is_expected.to normalize_digits_for(:b)
120
120
  end
121
121
 
@@ -127,7 +127,7 @@ RSpec.describe NormalizeDigits do
127
127
  context "Englishize except two attrs" do
128
128
  subject { instance_for(EnglishizeExceptTwo) }
129
129
 
130
- it "should englishize included strings" do
130
+ it "should normalize included strings" do
131
131
  is_expected.to normalize_digits_for(:d)
132
132
  end
133
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normalize_digits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aalyahya