numerify 0.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: 2ceaa4ea31dcb47991046a5ab07ed68a82aeb6c203a5f79c14541c605680bb4d
4
+ data.tar.gz: cc8bd2537a185f9508548e83b97f1cdf82ba5ac36875caf6e8a32a5bfadc91a0
5
+ SHA512:
6
+ metadata.gz: 59166e88b03fb7739bb4f832847d2ef15a4df64488a00c3076875db7742926e4788a00c882ebec5bc8c63893b54dca70a67391a80ed50bd3f85240463c962dd3
7
+ data.tar.gz: 4cc9c1013a259ad7f3afcd842c4c0ce97e9e52f4218cf6f1c36448907e9bdb9f7ffdf2c5bb4cf4b1642ae7f35508a7b158c1c7b109e62e043c08a6209b9b387f
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 200
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-30
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at wuletawwonte@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Wuletaw Wonte
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Numerify
2
+
3
+ > A Ruby gem designed to effortlessly convert numbers between Arabic and various world languages, including Geez, Roman, and Chineese.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem install numerify
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ These gem provides two approaches for converting numerals. The first is using Numerify.convert method as shown below.
14
+
15
+ ```bash
16
+ > require 'numerify'
17
+ => true
18
+ > Numerify.convert 123
19
+ => "፻፳፫"
20
+ > Numerify.convert(324, :roman)
21
+ => "CCCXXIV"
22
+ ```
23
+
24
+ The second method utilizes monkey patching, to extend the `String` and `Integer` class of Ruby. With this approach, you can directly call the `convert` method on a string or an integer object.
25
+
26
+ ```bash
27
+ > require 'numerify'
28
+ => true
29
+ > "123".convert
30
+ => "፻፳፫"
31
+ > 325.convert(:roman)
32
+ => "CCCXXIV"
33
+ ```
34
+ The list of numerals supported by this gem
35
+
36
+ geez: Geez,
37
+ roman: Roman,
38
+ chinese: Chinese,
39
+ thai: Thai,
40
+ bengali: Bengali,
41
+ devanagari: Devanagari,
42
+ gujarati: Gujarati,
43
+ gurmukhi: Gurmukhi,
44
+ kannada: Kannada,
45
+ khmer: Khmer,
46
+ lao: Lao,
47
+ malayalam: Malayalam,
48
+ myanmar: Myanmar
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wuletawwonte/numerify.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
+
58
+ ## Code of Conduct
59
+
60
+ Everyone interacting in the Numerify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wuletawwonte/numerify/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Bengali < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "০",
11
+ 1 => "১",
12
+ 2 => "২",
13
+ 3 => "৩",
14
+ 4 => "৪",
15
+ 5 => "৫",
16
+ 6 => "৬",
17
+ 7 => "৭",
18
+ 8 => "৮",
19
+ 9 => "৯"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+
5
+ # A class to convert to Chinese numerals.
6
+ class Chinese < NumeralBase
7
+ NUMERALS = {
8
+ 0 => "",
9
+ 1 => "一",
10
+ 2 => "二",
11
+ 3 => "三",
12
+ 4 => "四",
13
+ 5 => "五",
14
+ 6 => "六",
15
+ 7 => "七",
16
+ 8 => "八",
17
+ 9 => "九",
18
+ 10 => "十",
19
+ 100 => "百",
20
+ 1000 => "千",
21
+ 10_000 => "万",
22
+ 100_000_000 => "亿"
23
+ }.freeze
24
+
25
+ def convert(arabic_number_string)
26
+ arabic_number_string = arabic_number_string.to_s.strip
27
+ return "" if arabic_number_string.empty?
28
+ return "零" if arabic_number_string == "0"
29
+
30
+ convert_to_chinese arabic_number_string
31
+ end
32
+
33
+ private
34
+
35
+ def convert_to_chinese(value)
36
+ value.chars.map.with_index do |digit, i|
37
+ position = 10**(value.length - i - 1)
38
+ position == 1 || digit == "0" ? NUMERALS[digit.to_i] : NUMERALS[digit.to_i] + NUMERALS[position]
39
+ end.join
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # DecimalNumeralSystem module
4
+ module DecimalNumeral
5
+ private
6
+
7
+ def from_arabic(arabic_number_string, numeral_symbols)
8
+ arabic_number_string = arabic_number_string.to_s.strip
9
+ return "" if arabic_number_string.empty?
10
+
11
+ arabic_number_string.chars.map { |digit| numeral_symbols[digit.to_i] }.join
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Devanagari < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "०",
11
+ 1 => "१",
12
+ 2 => "२",
13
+ 3 => "३",
14
+ 4 => "४",
15
+ 5 => "५",
16
+ 6 => "६",
17
+ 7 => "७",
18
+ 8 => "८",
19
+ 9 => "९"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: false
2
+
3
+ require_relative "numeral_base"
4
+
5
+ # A class to convert to Geez script.
6
+ class Geez < NumeralBase
7
+ NUMERALS = {
8
+ 0 => "",
9
+ 1 => "፩",
10
+ 2 => "፪",
11
+ 3 => "፫",
12
+ 4 => "፬",
13
+ 5 => "፭",
14
+ 6 => "፮",
15
+ 7 => "፯",
16
+ 8 => "፰",
17
+ 9 => "፱",
18
+ 10 => "፲",
19
+ 20 => "፳",
20
+ 30 => "፴",
21
+ 40 => "፵",
22
+ 50 => "፶",
23
+ 60 => "፷",
24
+ 70 => "፸",
25
+ 80 => "፹",
26
+ 90 => "፺"
27
+ }.freeze
28
+
29
+ def convert(arabic_number_string)
30
+ arabic_number_string = arabic_number_string.to_s.strip
31
+
32
+ arabic_number_string = "0#{arabic_number_string}" if arabic_number_string.length.odd?
33
+ add_delimiter group_by_two arabic_number_string
34
+ end
35
+
36
+ private
37
+
38
+ # To Geez numeral conversion methods
39
+
40
+ def group_by_two(value)
41
+ value.split("").each_slice(2).to_a.map(&:join)
42
+ end
43
+
44
+ def single_digit_geez(number)
45
+ NUMERALS[number.to_i]
46
+ end
47
+
48
+ def double_digit_geez(number, skip_one: false)
49
+ return "" if skip_one
50
+
51
+ number.split("").map.with_index do |item, i|
52
+ i.zero? ? single_digit_geez(item.to_s << "0") : single_digit_geez(item)
53
+ end.join
54
+ end
55
+
56
+ def add_delimiter(grouped_string)
57
+ last_index = grouped_string.length - 1
58
+ last_index.downto(0) do |i|
59
+ if i == last_index
60
+ grouped_string[i] = double_digit_geez(grouped_string[i])
61
+ next
62
+ end
63
+
64
+ delimiter = i.even? ? "፻" : "፼"
65
+ grouped_string[i] = double_digit_geez(grouped_string[i], skip_one: grouped_string[i].to_i == 1) << delimiter
66
+ end
67
+ grouped_string.join
68
+ end
69
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Gujarati < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "૦",
11
+ 1 => "૧",
12
+ 2 => "૨",
13
+ 3 => "૩",
14
+ 4 => "૪",
15
+ 5 => "૫",
16
+ 6 => "૬",
17
+ 7 => "૭",
18
+ 8 => "૮",
19
+ 9 => "૯"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Gurmukhi < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "੦",
11
+ 1 => "੧",
12
+ 2 => "੨",
13
+ 3 => "੩",
14
+ 4 => "੪",
15
+ 5 => "੫",
16
+ 6 => "੬",
17
+ 7 => "੭",
18
+ 8 => "੮",
19
+ 9 => "੯"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Kannada < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "೦",
11
+ 1 => "೧",
12
+ 2 => "೨",
13
+ 3 => "೩",
14
+ 4 => "೪",
15
+ 5 => "೫",
16
+ 6 => "೬",
17
+ 7 => "೭",
18
+ 8 => "೮",
19
+ 9 => "೯"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Khmer < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "០",
11
+ 1 => "១",
12
+ 2 => "២",
13
+ 3 => "៣",
14
+ 4 => "៤",
15
+ 5 => "៥",
16
+ 6 => "៦",
17
+ 7 => "៧",
18
+ 8 => "៨",
19
+ 9 => "៩"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Lao < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "໐",
11
+ 1 => "໑",
12
+ 2 => "໒",
13
+ 3 => "໓",
14
+ 4 => "໔",
15
+ 5 => "໕",
16
+ 6 => "໖",
17
+ 7 => "໗",
18
+ 8 => "໘",
19
+ 9 => "໙"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Malayalam < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "൦",
11
+ 1 => "൧",
12
+ 2 => "൨",
13
+ 3 => "൩",
14
+ 4 => "൪",
15
+ 5 => "൫",
16
+ 6 => "൬",
17
+ 7 => "൭",
18
+ 8 => "൮",
19
+ 9 => "൯"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Myanmar < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "၀",
11
+ 1 => "၁",
12
+ 2 => "၂",
13
+ 3 => "၃",
14
+ 4 => "၄",
15
+ 5 => "၅",
16
+ 6 => "၆",
17
+ 7 => "၇",
18
+ 8 => "၈",
19
+ 9 => "၉"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A base class for numeral converters.
4
+ class NumeralBase
5
+ def convert
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+
5
+ # A class to convert to Roman numerals.
6
+ class Roman < NumeralBase
7
+ NUMERALS = {
8
+ 0 => "",
9
+ 1 => "I",
10
+ 5 => "V",
11
+ 10 => "X",
12
+ 50 => "L",
13
+ 100 => "C",
14
+ 500 => "D",
15
+ 1000 => "M"
16
+ }.freeze
17
+
18
+ def convert(arabic_number_string)
19
+ arabic_number_string = arabic_number_string.to_s.strip
20
+ return convert_to_roman_below_two_thousand(arabic_number_string) if arabic_number_string.to_i < 2000
21
+
22
+ ("M" * arabic_number_string.slice(0...-3).to_i) + convert_to_roman_below_two_thousand(arabic_number_string.slice(-3, 3))
23
+ end
24
+
25
+ private
26
+
27
+ def convert_to_roman_below_two_thousand(value)
28
+ value.split("").map.with_index do |digit, i|
29
+ position = 10**(value.length - i - 1)
30
+ target = digit.to_i * position
31
+ item = NUMERALS.keys.bsearch { |key| key >= target }
32
+ convert_digit_to_roman(target, position, item)
33
+ end.join
34
+ end
35
+
36
+ def convert_digit_to_roman(target, position, item)
37
+ case target
38
+ when item
39
+ NUMERALS[item]
40
+ when item - position
41
+ NUMERALS[position] + NUMERALS[item]
42
+ else
43
+ rep = ((target - item) / position) + 5
44
+ NUMERALS[item - (5 * position)] + (NUMERALS[position] * rep)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numeral_base"
4
+ require_relative "decimal_numeral"
5
+
6
+ # A class to convert to Thai numerals.
7
+ class Thai < NumeralBase
8
+ include DecimalNumeral
9
+ NUMERALS = {
10
+ 0 => "๐",
11
+ 1 => "๑",
12
+ 2 => "๒",
13
+ 3 => "๓",
14
+ 4 => "๔",
15
+ 5 => "๕",
16
+ 6 => "๖",
17
+ 7 => "๗",
18
+ 8 => "๘",
19
+ 9 => "๙"
20
+ }.freeze
21
+
22
+ def convert(arabic_number_string)
23
+ from_arabic(arabic_number_string, NUMERALS)
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../utils/factory"
4
+
5
+ # A patch to add the convert method to the Integer class.
6
+ class Integer
7
+ def convert(language = :geez)
8
+ factory = Numerify::Utils::NumeralFactory.new
9
+ factory.call(language).convert(self)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../utils/factory"
4
+
5
+ # A patch to add the convert method to the String class.
6
+ class String
7
+ def convert(language = :geez)
8
+ factory = Numerify::Utils::NumeralFactory.new
9
+ factory.call(language).convert(self)
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../converters/geez"
4
+ require_relative "../converters/roman"
5
+ require_relative "../converters/chinese"
6
+ require_relative "../converters/thai"
7
+ require_relative "../converters/bengali"
8
+ require_relative "../converters/devanagari"
9
+ require_relative "../converters/gujarati"
10
+ require_relative "../converters/gurmukhi"
11
+ require_relative "../converters/kannada"
12
+ require_relative "../converters/khmer"
13
+ require_relative "../converters/lao"
14
+ require_relative "../converters/malayalam"
15
+ require_relative "../converters/myanmar"
16
+
17
+ module Numerify
18
+ module Utils
19
+ # A factory class to create numeral objects.
20
+ class NumeralFactory
21
+ NUMERALCLASSES = {
22
+ geez: Geez,
23
+ roman: Roman,
24
+ chinese: Chinese,
25
+ thai: Thai,
26
+ bengali: Bengali,
27
+ devanagari: Devanagari,
28
+ gujarati: Gujarati,
29
+ gurmukhi: Gurmukhi,
30
+ kannada: Kannada,
31
+ khmer: Khmer,
32
+ lao: Lao,
33
+ malayalam: Malayalam,
34
+ myanmar: Myanmar
35
+ }.freeze
36
+
37
+ def call(language)
38
+ raise ArgumentError, "Invalid language" unless NUMERALCLASSES.key?(language.to_sym)
39
+
40
+ NUMERALCLASSES[language.to_sym].new
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Numerify
4
+ VERSION = "0.1.0"
5
+ end
data/lib/numerify.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "numerify/version"
4
+ require_relative "numerify/utils/factory"
5
+ require_relative "numerify/core_ext/string"
6
+ require_relative "numerify/core_ext/integer"
7
+
8
+ # A module to convert numbers to numerals.
9
+ module Numerify
10
+ class << self
11
+ def convert(value, language = :geez)
12
+ factory = Utils::NumeralFactory.new
13
+ factory.call(language).convert(value)
14
+ end
15
+ end
16
+ end
data/numerify.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/numerify/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "numerify"
7
+ spec.version = Numerify::VERSION
8
+ spec.authors = ["Wuletaw Wonte"]
9
+ spec.email = ["wuletawwonte@gmail.com"]
10
+
11
+ spec.summary = "A ruby gem that converts numbers from arabic to and from geez, chinese, greek, and many more."
12
+ spec.description = "An extraordinary Ruby gem designed to effortlessly convert numbers between Arabic and various world languages, including Geez, Chinese, Greek, and many more."
13
+ spec.homepage = "https://github.com/wuletawwonte/numerify.git"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/wuletawwonte/numerify.git"
21
+ spec.metadata["changelog_uri"] = "https://github.com/wuletawwonte/numerify/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+
38
+ # For more information and examples about making a new gem, check out our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
data/sig/numerify.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Numerify
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numerify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wuletaw Wonte
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: An extraordinary Ruby gem designed to effortlessly convert numbers between
14
+ Arabic and various world languages, including Geez, Chinese, Greek, and many more.
15
+ email:
16
+ - wuletawwonte@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/numerify.rb
28
+ - lib/numerify/converters/bengali.rb
29
+ - lib/numerify/converters/chinese.rb
30
+ - lib/numerify/converters/decimal_numeral.rb
31
+ - lib/numerify/converters/devanagari.rb
32
+ - lib/numerify/converters/geez.rb
33
+ - lib/numerify/converters/gujarati.rb
34
+ - lib/numerify/converters/gurmukhi.rb
35
+ - lib/numerify/converters/kannada.rb
36
+ - lib/numerify/converters/khmer.rb
37
+ - lib/numerify/converters/lao.rb
38
+ - lib/numerify/converters/malayalam.rb
39
+ - lib/numerify/converters/myanmar.rb
40
+ - lib/numerify/converters/numeral_base.rb
41
+ - lib/numerify/converters/roman.rb
42
+ - lib/numerify/converters/thai.rb
43
+ - lib/numerify/core_ext/integer.rb
44
+ - lib/numerify/core_ext/string.rb
45
+ - lib/numerify/utils/factory.rb
46
+ - lib/numerify/version.rb
47
+ - numerify.gemspec
48
+ - sig/numerify.rbs
49
+ homepage: https://github.com/wuletawwonte/numerify.git
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/wuletawwonte/numerify.git
55
+ source_code_uri: https://github.com/wuletawwonte/numerify.git
56
+ changelog_uri: https://github.com/wuletawwonte/numerify/blob/main/CHANGELOG.md
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.6.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.4.20
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A ruby gem that converts numbers from arabic to and from geez, chinese, greek,
76
+ and many more.
77
+ test_files: []