arabic-wordify 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 225232ca7bff186e1138abeb7524c00e460b233891f2c5f4e31583a0f2ec267f
4
+ data.tar.gz: 6dbf9d93c9653356500db73354559cd39ad2520f57d162c0f21566fd3552ad46
5
+ SHA512:
6
+ metadata.gz: 2c56df992a49cf2668e15fe5b190d8059630f16e68c81f57c56a5787907c8675904b4cd20a130a2331cae089796b7a9fdefd641031eda4f591cff94da6865896
7
+ data.tar.gz: 4447f70bffe00bee6c980f501908f4d28da1886c6200397e71ef01a05d5c3c50db27e33dc8aadd6037a75a4432b6b339ae566159cb381020cbbfa3a1affc8d45
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ - Converting various numbers to their word equivalents.
2
+ - Handling invalid inputs and ensuring appropriate errors are raised.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MAVEN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # arabic-wordify - Arabic Number to Words Converter
2
+
3
+ arabic-wordify is a Ruby gem that converts Arabic numbers into their word equivalents in Arabic. It supports numbers up to a septillion (1 followed by 24 zeros), including trillions, quadrillions, quintillions, sextillions, and septillions.
4
+
5
+ ## Features
6
+
7
+ - **Comprehensive Number Conversion**: Convert any number from 0 up to 10^24 into its Arabic word equivalent.
8
+ - **Arabic Digits Support**: Automatically converts Arabic digits (٠١٢٣٤٥٦٧٨٩) to English digits before conversion.
9
+ - **Error Handling**: Properly handles invalid inputs, such as non-integer values or empty inputs.
10
+ - **Support for Large Numbers**: Includes support for large number names such as million, billion, trillion, and beyond.
11
+
12
+ ## Installation
13
+
14
+ To install arabic-wordify, add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'arabic-wordify'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```bash
23
+ $ bundle install
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```bash
29
+ $ gem install arabic-wordify
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Using arabic-wordify in your Ruby application is simple. Here's an example:
35
+
36
+ ```ruby
37
+ require 'arabic-wordify'
38
+
39
+ number = "٢٢٠٣٤٢٢"
40
+
41
+ str = ArabicWordify::ArabicNumberWords.convert_to_text(number)
42
+ puts str
43
+ ```
44
+
45
+ This will output:
46
+
47
+ ```
48
+ اثنان مليون و مائتان و ثلاثة آلاف و أربعمائة و اثنان و عشرون
49
+ ```
50
+
51
+ ### Note on Arabic Digits
52
+
53
+ If you want to input Arabic digits directly without using quotation marks, please note that Ruby does not natively support this. You must input Arabic digits as strings (e.g., `"٢٢٠٣٤٢٢"`). The `arabic-wordify` gem will automatically convert these Arabic digits into their English equivalents before processing them.
54
+
55
+ ### Error Handling
56
+
57
+ arabic-wordify will raise an `ArabicWordifyError` if an invalid input is provided. For example:
58
+
59
+ ```ruby
60
+ begin
61
+ ArabicWordify.convert(nil)
62
+ rescue ArabicWordify::ArabicWordifyError => e
63
+ puts e.message
64
+ end
65
+ ```
66
+
67
+ This will output:
68
+
69
+ ```
70
+ Failed to convert number to words: Number cannot be nil or empty
71
+ ```
72
+
73
+ ## Development
74
+
75
+ To set up your development environment:
76
+
77
+ 1. Clone the repository:
78
+
79
+ ```bash
80
+ $ git clone https://github.com/Abo5/arabic-wordify.git
81
+ $ cd arabic-wordify
82
+ ```
83
+
84
+ 2. Install dependencies:
85
+
86
+ ```bash
87
+ $ bundle install
88
+ ```
89
+
90
+ 3. Run tests:
91
+
92
+ ```bash
93
+ $ bundle exec rspec
94
+ ```
95
+
96
+ ## Testing
97
+
98
+ arabic-wordify uses RSpec for testing. All test files are located in the `spec/` directory. To run the tests, execute:
99
+
100
+ ```bash
101
+ $ bundle exec rspec
102
+ ```
103
+
104
+ Example test cases include:
105
+
106
+ - Converting various numbers to their word equivalents.
107
+ - Handling invalid inputs and ensuring appropriate errors are raised.
108
+
109
+ ## Continuous Integration
110
+
111
+ arabic-wordify uses GitHub Actions for continuous integration. The configuration file is located at `.github/workflows/ruby.yml`. It ensures that every push and pull request is automatically tested on the specified Ruby versions.
112
+
113
+ ## Contributing
114
+
115
+ Bug reports and pull requests are welcome on GitHub at [arabic-wordify repository](https://github.com/Abo5/arabic-wordify). This project is intended to be a safe, welcoming space for collaboration.
116
+
117
+ ## License
118
+
119
+ arabic-wordify is available as open-source under the terms of the [MIT License](https://github.com/Abo5/arabic-wordify/blob/main/LICENSE).
120
+
121
+ ## Future Plans
122
+
123
+ - **Internationalization**: Extend support to more languages.
124
+ - **Additional Number Formats**: Support for ordinal numbers and other formats.
125
+
126
+ ## Support
127
+
128
+ If you encounter any issues or have questions, please open an issue on GitHub or contact the maintainers.
129
+
130
+ ## Acknowledgements
131
+
132
+ This project was inspired by the need for a robust Arabic number-to-word converter that supports large numbers and provides accurate results in the Arabic language.# arabic-wordify
@@ -0,0 +1,15 @@
1
+ # lib/Arabic-Wordify.rb
2
+ require_relative 'ArabicWordify/arabic_number_words.rb'
3
+ require_relative 'ArabicWordify/error'
4
+
5
+ module ArabicWordify
6
+ def self.convert(number)
7
+ raise ArgumentError, 'Number cannot be nil or empty' if number.nil? || number.to_s.empty?
8
+ raise ArgumentError, 'Number must be an integer' unless number.is_a?(Integer)
9
+
10
+ ArabicWordify::ArabicNumberWords.convert_to_text(number)
11
+ rescue => e
12
+ raise ArabicWordifyError, "Failed to convert number to words: #{e.message}"
13
+ end
14
+
15
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'units'
2
+ module ArabicWordify
3
+ class ArabicNumberWords
4
+ def self.convert_to_text(number)
5
+ number = convert_arabic_num_to_english_num(number)
6
+ return 'صفر' if number.to_i.zero?
7
+
8
+ parts = []
9
+ thousand_index = 0
10
+
11
+ while number > 0
12
+ part = number % 1000
13
+ unless part.zero?
14
+ part_text = convert_hundreds(part)
15
+ part_text += " #{THOUSANDS[thousand_index]}" unless thousand_index.zero?
16
+ parts.unshift(part_text)
17
+ end
18
+ number /= 1000
19
+ thousand_index += 1
20
+ end
21
+
22
+ parts.join(' و ')
23
+ end
24
+
25
+ private
26
+
27
+ def self.convert_hundreds(number)
28
+ return UNITS[number] if number <= 19
29
+
30
+ hundreds = number / 100
31
+ tens = number % 100
32
+ words = []
33
+
34
+ words << HUNDREDS[hundreds * 100] if hundreds > 0
35
+
36
+ if tens > 0
37
+ if tens <= 19
38
+ words << UNITS[tens]
39
+ else
40
+ ones = tens % 10
41
+ words << UNITS[ones] if ones > 0
42
+ words << TENS[(tens / 10) * 10]
43
+ end
44
+ end
45
+
46
+ words.join(' و ')
47
+ end
48
+
49
+ def self.convert_arabic_num_to_english_num(number)
50
+ number.to_s.tr('٠١٢٣٤٥٦٧٨٩', '0123456789').to_i
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # lib/ArabicWordify/error.rb
2
+ module ArabicWordify
3
+ class ArabicWordifyError < StandardError
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ UNITS = {
2
+ 0 => '', 1 => 'واحد', 2 => 'اثنان', 3 => 'ثلاثة', 4 => 'أربعة', 5 => 'خمسة',
3
+ 6 => 'ستة', 7 => 'سبعة', 8 => 'ثمانية', 9 => 'تسعة', 10 => 'عشرة',
4
+ 11 => 'أحد عشر', 12 => 'اثنا عشر', 13 => 'ثلاثة عشر', 14 => 'أربعة عشر', 15 => 'خمسة عشر',
5
+ 16 => 'ستة عشر', 17 => 'سبعة عشر', 18 => 'ثمانية عشر', 19 => 'تسعة عشر'
6
+ }
7
+
8
+ TENS = {
9
+ 20 => 'عشرون', 30 => 'ثلاثون', 40 => 'أربعون', 50 => 'خمسون',
10
+ 60 => 'ستون', 70 => 'سبعون', 80 => 'ثمانون', 90 => 'تسعون'
11
+ }
12
+
13
+ HUNDREDS = {
14
+ 100 => 'مائة', 200 => 'مئتان', 300 => 'ثلاثمائة', 400 => 'أربعمائة', 500 => 'خمسمائة',
15
+ 600 => 'ستمائة', 700 => 'سبعمائة', 800 => 'ثمانمائة', 900 => 'تسعمائة'
16
+ }
17
+
18
+ THOUSANDS = ['', 'ألف', 'مليون', 'مليار', 'تريليون', 'كوادريليون', 'كوينتليون', 'سكستليون', 'سبتيليون']
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arabic-wordify
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - MAVEN
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.10'
55
+ description: Arabic-Wordify is a Ruby gem designed to convert Arabic numbers (integers)
56
+ into their word equivalents in Arabic, supporting numbers from zero up to a septillion.
57
+ email: qppn@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE.txt
64
+ - README.md
65
+ - lib/Arabic-Wordify.rb
66
+ - lib/ArabicWordify/arabic_number_words.rb
67
+ - lib/ArabicWordify/error.rb
68
+ - lib/ArabicWordify/units.rb
69
+ homepage: https://github.com/Abo5/arabic-wordify
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/Abo5/arabic-wordify
74
+ source_code_uri: https://github.com/Abo5/arabic-wordify
75
+ changelog_uri: https://github.com/Abo5/arabic-wordify/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.3.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Ruby gem that converts Arabic numbers into their word equivalents in Arabic.
95
+ test_files: []