mirror of
https://github.com/ditkrg/number-to-kurdish-words.git
synced 2026-01-22 13:56:52 +00:00
First commit
This commit is contained in:
commit
1893b82cc0
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/.bundle/
|
||||
/.yardoc
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
|
||||
# rspec failure tracking
|
||||
.rspec_status
|
||||
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
language: ruby
|
||||
cache: bundler
|
||||
rvm:
|
||||
- 2.5.1
|
||||
before_install: gem install bundler -v 2.1.4
|
||||
74
CODE_OF_CONDUCT.md
Normal file
74
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,74 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers 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, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at broosk.edogawa@gmail.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [https://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: https://contributor-covenant.org
|
||||
[version]: https://contributor-covenant.org/version/1/4/
|
||||
9
Gemfile
Normal file
9
Gemfile
Normal file
@ -0,0 +1,9 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in numbers_to_kurdish_words.gemspec
|
||||
gemspec
|
||||
|
||||
gem "rake", "~> 12.0"
|
||||
gem "rspec", "~> 3.0"
|
||||
gem "coveralls", require: false
|
||||
|
||||
82
Gemfile.lock
Normal file
82
Gemfile.lock
Normal file
@ -0,0 +1,82 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
numbers_to_kurdish_words (0.1.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.1)
|
||||
coderay (1.1.3)
|
||||
coveralls (0.8.23)
|
||||
json (>= 1.8, < 3)
|
||||
simplecov (~> 0.16.1)
|
||||
term-ansicolor (~> 1.3)
|
||||
thor (>= 0.19.4, < 2.0)
|
||||
tins (~> 1.6)
|
||||
diff-lcs (1.4.4)
|
||||
docile (1.3.5)
|
||||
json (2.5.1)
|
||||
method_source (1.0.0)
|
||||
parallel (1.20.1)
|
||||
parser (3.0.0.0)
|
||||
ast (~> 2.4.1)
|
||||
pry (0.13.1)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
rainbow (3.0.0)
|
||||
rake (12.3.3)
|
||||
regexp_parser (2.0.3)
|
||||
rexml (3.2.4)
|
||||
rspec (3.10.0)
|
||||
rspec-core (~> 3.10.0)
|
||||
rspec-expectations (~> 3.10.0)
|
||||
rspec-mocks (~> 3.10.0)
|
||||
rspec-core (3.10.1)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-expectations (3.10.1)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-mocks (3.10.1)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-support (3.10.1)
|
||||
rubocop (1.8.1)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.0.0.0)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.0)
|
||||
rexml
|
||||
rubocop-ast (>= 1.2.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 1.4.0, < 3.0)
|
||||
rubocop-ast (1.4.0)
|
||||
parser (>= 2.7.1.5)
|
||||
ruby-progressbar (1.11.0)
|
||||
simplecov (0.16.1)
|
||||
docile (~> 1.1)
|
||||
json (>= 1.8, < 3)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.2)
|
||||
sync (0.5.0)
|
||||
term-ansicolor (1.7.1)
|
||||
tins (~> 1.0)
|
||||
thor (1.0.1)
|
||||
tins (1.28.0)
|
||||
sync
|
||||
unicode-display_width (2.0.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bundler (~> 2.1.4)
|
||||
coveralls
|
||||
numbers_to_kurdish_words!
|
||||
pry
|
||||
rake (~> 12.0)
|
||||
rspec (~> 3.0)
|
||||
rubocop
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 Brusk Hamarash
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
44
README.md
Normal file
44
README.md
Normal file
@ -0,0 +1,44 @@
|
||||
# NumbersToKurdishWords
|
||||
|
||||
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/numbers_to_kurdish_words`. To experiment with that code, run `bin/console` for an interactive prompt.
|
||||
|
||||
TODO: Delete this and the text above, and describe your gem
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'numbers_to_kurdish_words'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
|
||||
$ bundle install
|
||||
|
||||
Or install it yourself as:
|
||||
|
||||
$ gem install numbers_to_kurdish_words
|
||||
|
||||
## Usage
|
||||
|
||||
TODO: Write usage instructions here
|
||||
|
||||
## Development
|
||||
|
||||
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.
|
||||
|
||||
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).
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/numbers_to_kurdish_words. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/numbers_to_kurdish_words/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
|
||||
## License
|
||||
|
||||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
Everyone interacting in the NumbersToKurdishWords project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/numbers_to_kurdish_words/blob/master/CODE_OF_CONDUCT.md).
|
||||
6
Rakefile
Normal file
6
Rakefile
Normal file
@ -0,0 +1,6 @@
|
||||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :default => :spec
|
||||
14
bin/console
Executable file
14
bin/console
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require "bundler/setup"
|
||||
require "numbers_to_kurdish_words"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
||||
# (If you use this, don't forget to add pry to your Gemfile!)
|
||||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require "irb"
|
||||
IRB.start(__FILE__)
|
||||
8
bin/setup
Executable file
8
bin/setup
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
set -vx
|
||||
|
||||
bundle install
|
||||
|
||||
# Do any other automated setup that you need to do here
|
||||
63
lib/numbers_to_kurdish_words.rb
Normal file
63
lib/numbers_to_kurdish_words.rb
Normal file
@ -0,0 +1,63 @@
|
||||
require "numbers_to_kurdish_words/version"
|
||||
|
||||
module NumbersToKurdishWords
|
||||
class Error < StandardError; end
|
||||
# require "to_words/version"
|
||||
def to_words(number = self, level = 0)
|
||||
ones = ["یەک", "دوو", "سێ", "چوار", "پێنج", "شەش", "حەوت", "هەشت", "نۆ"];
|
||||
ten = ["دە", "یازدە", "دوازدە", "سیازدە", "چواردە", "پازدە", "شازدە", "حەفدە", "هەژدە", "نۆزدە"];
|
||||
tens = ["بیست", "سی", "چل", "پەنجا", "شەست", "حەفتا", "هەشتا", "نەوەد"];
|
||||
hundreds = ["سەد", "دوو سەد", "سێ سەد", "چوار سەد", "پێنج سەد", "شەش سەد", "حەوت سەد", "هەشت سەد", "نۆ سەد"];
|
||||
|
||||
result = "";
|
||||
|
||||
return "" if number === nil
|
||||
|
||||
if number < 0
|
||||
number = number * -1;
|
||||
return "سالب " + number.to_words
|
||||
end
|
||||
|
||||
if number === 0
|
||||
if level === 0
|
||||
return "سفر";
|
||||
else
|
||||
return "";
|
||||
end
|
||||
end
|
||||
|
||||
if level > 0
|
||||
result += " و ";
|
||||
level -= 1;
|
||||
end
|
||||
|
||||
if number < 10
|
||||
result += ones[number - 1];
|
||||
elsif (number < 20)
|
||||
result += ten[number - 10];
|
||||
elsif (number < 100)
|
||||
result += tens[(number / 10).floor - 2] + to_words(number % 10, level + 1);
|
||||
elsif (number < 1000)
|
||||
result += hundreds[(number / 100).floor - 1] + to_words(number % 100, level + 1);
|
||||
elsif (number < 1000000)
|
||||
result += (number / 1000 < 2 ? '' : to_words((number / 1000).floor, level)) + " هەزار" + to_words(number % 1000, level + 1);
|
||||
elsif (number < 1000000000)
|
||||
result += to_words((number / 1000000).floor, level) + " ملیۆن" + to_words(number % 1000000, level + 1);
|
||||
elsif (number < 1000000000000)
|
||||
result += to_words((number / 1000000000).floor, level) + " ملیارد" + to_words(number % 1000000000, level + 1);
|
||||
elsif (number < 1000000000000000)
|
||||
result += to_words((number / 1000000000000).floor, level) + " ترلیۆن" + to_words(number % 1000000000000, level + 1);
|
||||
end
|
||||
|
||||
return result;
|
||||
end
|
||||
end
|
||||
|
||||
INTEGER_KLASS = 1.class # Fixnum before Ruby 2.4, Integer from Ruby 2.4
|
||||
class INTEGER_KLASS
|
||||
include NumbersToKurdishWords
|
||||
end
|
||||
|
||||
class String
|
||||
include NumbersToKurdishWords
|
||||
end
|
||||
3
lib/numbers_to_kurdish_words/version.rb
Normal file
3
lib/numbers_to_kurdish_words/version.rb
Normal file
@ -0,0 +1,3 @@
|
||||
module NumbersToKurdishWords
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
35
numbers_to_kurdish_words.gemspec
Normal file
35
numbers_to_kurdish_words.gemspec
Normal file
@ -0,0 +1,35 @@
|
||||
require_relative 'lib/numbers_to_kurdish_words/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "numbers_to_kurdish_words"
|
||||
spec.version = NumbersToKurdishWords::VERSION
|
||||
spec.authors = ["Brusk Hamarash"]
|
||||
spec.email = ["broosk.edogawa@gmail.com"]
|
||||
|
||||
spec.summary = %q{Translates integers into Kurdish words}
|
||||
spec.description = %q{Translates integers into Kurdish words}
|
||||
spec.homepage = "https://github.com/ditdevtools/number-to-kurdish-words"
|
||||
spec.license = "MIT"
|
||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
||||
|
||||
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
||||
|
||||
spec.metadata["homepage_uri"] = spec.homepage
|
||||
spec.metadata["source_code_uri"] = "https://github.com/ditdevtools/number-to-kurdish-words"
|
||||
spec.metadata["changelog_uri"] = "https://github.com/ditdevtools/number-to-kurdish-words/CHANGE.md"
|
||||
|
||||
# Specify which files should be added to the gem when it is released.
|
||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
||||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||
end
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
spec.add_development_dependency "bundler", "~> 2.1.4"
|
||||
spec.add_development_dependency "rake"
|
||||
spec.add_development_dependency "rubocop"
|
||||
spec.add_development_dependency "rspec"
|
||||
spec.add_development_dependency "pry"
|
||||
|
||||
end
|
||||
70
spec/numbers_to_kurdish_words_spec.rb
Normal file
70
spec/numbers_to_kurdish_words_spec.rb
Normal file
@ -0,0 +1,70 @@
|
||||
RSpec.describe NumbersToKurdishWords do
|
||||
it "has a version number" do
|
||||
expect(NumbersToKurdishWords::VERSION).not_to be nil
|
||||
end
|
||||
|
||||
it "converts 1 to یەک" do
|
||||
expect(1.to_words).to eq("یەک")
|
||||
end
|
||||
|
||||
it "converts 11 to یازدە" do
|
||||
expect(11.to_words).to eq("یازدە")
|
||||
end
|
||||
|
||||
it "converts 25 to بیست و پێنج" do
|
||||
expect(25.to_words).to eq("بیست و پێنج")
|
||||
end
|
||||
|
||||
it "converts 88 to هەشتا و هەشت" do
|
||||
expect(88.to_words).to eq("هەشتا و هەشت")
|
||||
end
|
||||
|
||||
it "converts 10 to دە" do
|
||||
expect(10.to_words).to eq("دە")
|
||||
end
|
||||
|
||||
it "converts 100 to سەد" do
|
||||
expect(100.to_words).to eq("سەد")
|
||||
end
|
||||
|
||||
it "converts 104 to سەد و چوار" do
|
||||
expect(104.to_words).to eq("سەد و چوار")
|
||||
end
|
||||
|
||||
it "converts 110 to سەد و دە" do
|
||||
expect(110.to_words).to eq("سەد و دە")
|
||||
end
|
||||
|
||||
it "converts 115 to سەد و پازدە" do
|
||||
expect(115.to_words).to eq("سەد و پازدە")
|
||||
end
|
||||
|
||||
it "converts 555 to پێنج سەد و پەنجا و پێنج" do
|
||||
expect(555.to_words).to eq("پێنج سەد و پەنجا و پێنج")
|
||||
end
|
||||
|
||||
it "converts 1005 to هەزار و پێنج" do
|
||||
expect(1005.to_words.strip).to eq("هەزار و پێنج")
|
||||
end
|
||||
|
||||
it "converts 1012 to هەزار و دوازدە" do
|
||||
expect(1012.to_words.strip).to eq("هەزار و دوازدە")
|
||||
end
|
||||
|
||||
it "converts 1042 to هەزار و چل و دوو" do
|
||||
expect(1042.to_words.strip).to eq("هەزار و چل و دوو")
|
||||
end
|
||||
|
||||
it "converts 1122 to هەزار و سەد و بیست و دوو" do
|
||||
expect(1122.to_words.strip).to eq("هەزار و سەد و بیست و دوو")
|
||||
end
|
||||
|
||||
it "converts 25367 to بیست و پێنج هەزار و سێ سەد و شەست و حەوت" do
|
||||
expect(25367.to_words.strip).to eq("بیست و پێنج هەزار و سێ سەد و شەست و حەوت")
|
||||
end
|
||||
|
||||
it "converts 100012 to سەد هەزار و دوازدە" do
|
||||
expect(100012.to_words.strip).to eq("سەد هەزار و دوازدە")
|
||||
end
|
||||
|
||||
end
|
||||
16
spec/spec_helper.rb
Normal file
16
spec/spec_helper.rb
Normal file
@ -0,0 +1,16 @@
|
||||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
||||
|
||||
require "bundler/setup"
|
||||
require "numbers_to_kurdish_words"
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Enable flags like --only-failures and --next-failure
|
||||
config.example_status_persistence_file_path = ".rspec_status"
|
||||
|
||||
# Disable RSpec exposing methods globally on `Module` and `main`
|
||||
config.disable_monkey_patching!
|
||||
|
||||
config.expect_with :rspec do |c|
|
||||
c.syntax = :expect
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user