turkish_number 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +22 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/turkish_number.rb +62 -0
- data/lib/turkish_number/version.rb +3 -0
- data/turkish_number.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c253bfd75e7069a6431204c72839b814a4f0e3f
|
4
|
+
data.tar.gz: 9a680e179d0205dc38edef326821f09f33f8c5a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d185662e2954dcfd8f4f43258faa21e985697b45174d91c157d4924915a95b533cb3152fe9acb8aeb20d10db5a9596241693c8efc9321021a4514230a631547
|
7
|
+
data.tar.gz: 77ca01b2adcf2f1579eae0a1c5fe408209652810372b67f3d944fb80e1d7f516affee3a06feccceb9576fc869f8b056aa63fc066d8b412d4243df2ed2525222b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jonathan Hinkle
|
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,22 @@
|
|
1
|
+
# TurkishNumber
|
2
|
+
|
3
|
+
This tool performs the very small task of turning a number (e.g. 25) into words in Turkish (e.g. "yırmı beş").
|
4
|
+
|
5
|
+
It currently works for positive numbers less than one trillion.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
TurkishNumber.to_words(2096) # => "iki bin doksan altı"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Development
|
14
|
+
|
15
|
+
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.
|
16
|
+
|
17
|
+
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).
|
18
|
+
|
19
|
+
## License
|
20
|
+
|
21
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
22
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "turkish_number"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "turkish_number/version"
|
2
|
+
|
3
|
+
module TurkishNumber
|
4
|
+
|
5
|
+
MINIMUM_HANDLEABLE_NUMBER = 0
|
6
|
+
MAXIMUM_HANDLEABLE_NUMBER = 999_999_999_999
|
7
|
+
BREAKNUMBERS = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1_000, 1_000_000, 1_000_000_000].sort!.reverse!.freeze
|
8
|
+
MAPPINGS = {
|
9
|
+
0 => 'sıfır',
|
10
|
+
1 => 'bir',
|
11
|
+
2 => 'iki',
|
12
|
+
3 => 'üç',
|
13
|
+
4 => 'dört',
|
14
|
+
5 => 'beş',
|
15
|
+
6 => 'altı',
|
16
|
+
7 => 'yedi',
|
17
|
+
8 => 'sekiz',
|
18
|
+
9 => 'dokuz',
|
19
|
+
10 => 'on',
|
20
|
+
20 => 'yirmi',
|
21
|
+
30 => 'otuz',
|
22
|
+
40 => 'kırk',
|
23
|
+
50 => 'elli',
|
24
|
+
60 => 'altmış',
|
25
|
+
70 => 'yetmiş',
|
26
|
+
80 => 'seksen',
|
27
|
+
90 => 'doksan',
|
28
|
+
100 => 'yüz',
|
29
|
+
1_000 => 'bin',
|
30
|
+
1_000_000 => 'milyon',
|
31
|
+
1_000_000_000 => 'milyar'
|
32
|
+
}.freeze
|
33
|
+
|
34
|
+
def self.to_words(number)
|
35
|
+
begin
|
36
|
+
number = Integer(number)
|
37
|
+
rescue ArgumentError
|
38
|
+
raise ArgumentError, "unable to convert #{number.inspect} to an Integer"
|
39
|
+
end
|
40
|
+
|
41
|
+
raise ArgumentError, "#{number} is too small" if number < MINIMUM_HANDLEABLE_NUMBER
|
42
|
+
raise ArgumentError, "#{number} is too big" if number > MAXIMUM_HANDLEABLE_NUMBER
|
43
|
+
|
44
|
+
return MAPPINGS.fetch(number) if MAPPINGS.key?(number)
|
45
|
+
|
46
|
+
breaknumber = BREAKNUMBERS.detect { |b| b < number }
|
47
|
+
unless breaknumber
|
48
|
+
raise "no breaknumber found that is less than #{number}"
|
49
|
+
end
|
50
|
+
|
51
|
+
breaknumber_multiplier = number / breaknumber
|
52
|
+
|
53
|
+
leftovers = number - (breaknumber * breaknumber_multiplier)
|
54
|
+
|
55
|
+
components = [breaknumber]
|
56
|
+
components << leftovers unless leftovers == 0
|
57
|
+
components.unshift(breaknumber_multiplier) unless breaknumber_multiplier == 1
|
58
|
+
|
59
|
+
components.map{|component_number| TurkishNumber.to_words(component_number)}.join(' ')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'turkish_number/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "turkish_number"
|
8
|
+
spec.version = TurkishNumber::VERSION
|
9
|
+
spec.authors = ["Jonathan Hinkle"]
|
10
|
+
spec.email = ["hello@hynkle.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{turn integers into the Turkish words for that number}
|
13
|
+
spec.description = %q{turn integers into the Turkish words for that number}
|
14
|
+
spec.homepage = "https://github.com/hynkle/turkish_number"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turkish_number
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Hinkle
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-16 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: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: turn integers into the Turkish words for that number
|
56
|
+
email:
|
57
|
+
- hello@hynkle.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/turkish_number.rb
|
71
|
+
- lib/turkish_number/version.rb
|
72
|
+
- turkish_number.gemspec
|
73
|
+
homepage: https://github.com/hynkle/turkish_number
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.5.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: turn integers into the Turkish words for that number
|
97
|
+
test_files: []
|