kabal 0.0.2
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +23 -0
- data/.travis.yml +3 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +11 -0
- data/kabal.gemspec +22 -0
- data/lib/kabal.rb +12 -0
- data/lib/kabal/languages/language.rb +10 -0
- data/lib/kabal/languages/russian.rb +72 -0
- data/lib/kabal/supported_languages.rb +4 -0
- data/lib/kabal/version.rb +3 -0
- data/test/lib/kabal_test.rb +36 -0
- data/test/test_helper.rb +15 -0
- data/yaml/languages.yml +1 -0
- data/yaml/languages/ru.yml +81 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a95098432439efebdd18b4719132bf1c2ebfa9c
|
4
|
+
data.tar.gz: b41d9d94671b75fdb212cc178e0f9f06ded2c35b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 587ef89f29e52a3c17992e817246a958ac42111738091cc782b5baf35fcc33735b5e316568442ba54f7bab63db08b0f4cb60a621dc4156c8bc8a64e8740f6788
|
7
|
+
data.tar.gz: b5f44d3d17f55fc17b8273325a690b8537b8b6d313c3c7344c95e849583ba133e421d70a0fd2d70c4b1573a52a1ceaefe02d37e1f87233aa046d3ad9a3f331fd
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: LhEcM6Hpg35A4nWuxweYsCqMqMHaLApbC
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.swp
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in kabal.gemspec
|
4
|
+
gemspec
|
5
|
+
gem 'turn'
|
6
|
+
gem 'pry'
|
7
|
+
gem 'tconsole', git: "git://github.com/gma/tconsole"
|
8
|
+
gem 'coveralls', require: false
|
9
|
+
gem 'simplecov'
|
10
|
+
gem 'minitest', '4.7.5'
|
11
|
+
gem 'russian'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 pavel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Kabal
|
2
|
+
|
3
|
+
[](https://travis-ci.org/kalashnikovisme/kabal)[](https://coveralls.io/r/kalashnikovisme/kabal)
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'kabal'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kabal
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/kabal/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/kabal.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kabal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kabal"
|
8
|
+
spec.version = Kabal::VERSION
|
9
|
+
spec.authors = ["pavel"]
|
10
|
+
spec.email = ["kalashnikovisme@gmail.com"]
|
11
|
+
spec.summary = %q{Number To Text Helper}
|
12
|
+
spec.description = %q{Kabal allows you to translate numbers into text.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
end
|
data/lib/kabal.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'kabal/languages/language'
|
2
|
+
|
3
|
+
class Kabal::Russian < Kabal::Language
|
4
|
+
def convert(number)
|
5
|
+
return single(number) if number >= 0 and number <= 19
|
6
|
+
return two_words(number) if number >= 20 and number <= 99
|
7
|
+
return three_words(number) if number >= 100 and number <= 999
|
8
|
+
ten_powers(number) if number >= 1000
|
9
|
+
end
|
10
|
+
|
11
|
+
def single(number)
|
12
|
+
if (number == 1 or number == 2) and @count and @count / 10 != 1 and @number_order == 3
|
13
|
+
names[lang]["single_feminine"][@count % 10]
|
14
|
+
else
|
15
|
+
names[lang]["single"][number]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def two_words(number)
|
20
|
+
return single number if number <= 19
|
21
|
+
number_name = names[lang]["two_words"][number / 10]
|
22
|
+
number_name += " " + single(number % 10) if (number % 10 != 0)
|
23
|
+
number_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def three_words(number)
|
27
|
+
if number / 100 == 0
|
28
|
+
return two_words number
|
29
|
+
end
|
30
|
+
number_name = names[lang]["three_words"][number / 100]
|
31
|
+
return number_name += " " + two_words(number % 100) if (number % 100 >= 20)
|
32
|
+
return number_name += " " + single(number % 100) if (number % 100 != 0)
|
33
|
+
number_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def ten_powers(number)
|
37
|
+
#FIXME find better way
|
38
|
+
@number_order = ((number.to_s.length - 1) / 3) * 3
|
39
|
+
if @number_order < 3
|
40
|
+
unless number == 0
|
41
|
+
@number_name += " " + three_words(number % 1000)
|
42
|
+
end
|
43
|
+
return @number_name
|
44
|
+
end
|
45
|
+
@count = number / (10 ** @number_order)
|
46
|
+
if number_is_google?
|
47
|
+
return names[lang]["ten_powers"][100]
|
48
|
+
end
|
49
|
+
if @number_name.nil?
|
50
|
+
@number_name = count_name + " " + name_with_declination(names[lang]["ten_powers"][@number_order])
|
51
|
+
elsif @count != 0
|
52
|
+
@number_name += " " + count_name + " " + name_with_declination(names[lang]["ten_powers"][@number_order])
|
53
|
+
end
|
54
|
+
ten_powers(number % (10 ** @number_order))
|
55
|
+
end
|
56
|
+
|
57
|
+
def count_name
|
58
|
+
three_words @count
|
59
|
+
end
|
60
|
+
|
61
|
+
def name_with_declination(ten_power_name)
|
62
|
+
if ten_power_name[-1, 1] == "а"
|
63
|
+
Russian.p(@count, ten_power_name, ten_power_name[0..4] + "и", ten_power_name[0..4])
|
64
|
+
else
|
65
|
+
Russian.p(@count, ten_power_name, ten_power_name + "а", ten_power_name + "ов")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def number_is_google?
|
70
|
+
@count == 10 and @number_order == 99
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
include Kabal
|
4
|
+
|
5
|
+
class KabalTest < TestCase
|
6
|
+
def test_to_text_with_single_number
|
7
|
+
assert_equal Kabal.to_text(1), "один"
|
8
|
+
end
|
9
|
+
def test_to_text_with_two_words_number
|
10
|
+
assert_equal Kabal.to_text(25), "двадцать пять"
|
11
|
+
end
|
12
|
+
def test_to_text_with_three_words_number
|
13
|
+
assert_equal Kabal.to_text(625), "шестьсот двадцать пять"
|
14
|
+
end
|
15
|
+
def test_to_text_with_ten_powers
|
16
|
+
assert_equal Kabal.to_text(125625), "сто двадцать пять тысяч шестьсот двадцать пять"
|
17
|
+
end
|
18
|
+
def test_to_text_with_ten_powers_millions
|
19
|
+
assert_equal Kabal.to_text(125125625), "сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
|
20
|
+
end
|
21
|
+
def test_to_text_with_ten_powers_some_number
|
22
|
+
assert_equal Kabal.to_text(1000001), "один миллион один"
|
23
|
+
end
|
24
|
+
def test_to_text_with_google
|
25
|
+
assert_equal Kabal.to_text(10 ** 100), "гугол"
|
26
|
+
end
|
27
|
+
def test_to_text_with_three_words_without_second_order
|
28
|
+
assert_equal Kabal.to_text(101), "сто один"
|
29
|
+
end
|
30
|
+
def test_to_text_with_three_words_without_first_and_second_order
|
31
|
+
assert_equal Kabal.to_text(200), "двести"
|
32
|
+
end
|
33
|
+
def test_to_text_with_thousands
|
34
|
+
assert_equal Kabal.to_text(22000), "двадцать две тысячи"
|
35
|
+
end
|
36
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
if ENV["TRAVIS"]
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
end
|
6
|
+
require 'simplecov'
|
7
|
+
ENV["RAILS_ENV"] = "test"
|
8
|
+
SimpleCov.start('rails') if ENV["COVERAGE"]
|
9
|
+
|
10
|
+
Bundler.require
|
11
|
+
|
12
|
+
MiniTest::Unit.autorun
|
13
|
+
|
14
|
+
class TestCase < MiniTest::Unit::TestCase
|
15
|
+
end
|
data/yaml/languages.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Russian: "ru"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
ru:
|
2
|
+
single:
|
3
|
+
0: ноль
|
4
|
+
1: один
|
5
|
+
2: два
|
6
|
+
3: три
|
7
|
+
4: четыре
|
8
|
+
5: пять
|
9
|
+
6: шесть
|
10
|
+
7: семь
|
11
|
+
8: восемь
|
12
|
+
9: девять
|
13
|
+
10: десять
|
14
|
+
11: одиннадцать
|
15
|
+
12: двенадцать
|
16
|
+
13: тринадцать
|
17
|
+
14: четырнадцать
|
18
|
+
15: пятнадцать
|
19
|
+
16: шестнадцать
|
20
|
+
17: семьнадцать
|
21
|
+
18: восемьнадцать
|
22
|
+
19: девятнадцать
|
23
|
+
two_words:
|
24
|
+
2: двадцать
|
25
|
+
3: тридцать
|
26
|
+
4: сорок
|
27
|
+
5: пятьдесят
|
28
|
+
6: шестьдесят
|
29
|
+
7: семьдесят
|
30
|
+
8: восемьдесят
|
31
|
+
9: девяносто
|
32
|
+
three_words:
|
33
|
+
1: сто
|
34
|
+
2: двести
|
35
|
+
3: триста
|
36
|
+
4: четыреста
|
37
|
+
5: пятьсот
|
38
|
+
6: шестьсот
|
39
|
+
7: семьсот
|
40
|
+
8: восемьсот
|
41
|
+
9: девятьсот
|
42
|
+
ten_powers:
|
43
|
+
0: один
|
44
|
+
1: десять
|
45
|
+
2: сто
|
46
|
+
3: тысяча
|
47
|
+
6: миллион
|
48
|
+
9: миллиард
|
49
|
+
12: триллион
|
50
|
+
15: квадраллион
|
51
|
+
18: квинтиллион
|
52
|
+
21: секстиллион
|
53
|
+
24: септиллион
|
54
|
+
27: октиллион
|
55
|
+
30: нониллион
|
56
|
+
33: дециллион
|
57
|
+
36: андециллион
|
58
|
+
39: дуодециллион
|
59
|
+
42: тредециллион
|
60
|
+
45: квиндециллион
|
61
|
+
51: сексдециллион
|
62
|
+
54: септемдециллион
|
63
|
+
57: октодециллион
|
64
|
+
60: новемдециллион
|
65
|
+
63: вигинтиллион
|
66
|
+
66: анвигинтиллион
|
67
|
+
69: дуовигинтиллион
|
68
|
+
72: тревигинтиллион
|
69
|
+
75: кватторвигинтиллион
|
70
|
+
78: квинвигинтиллион
|
71
|
+
81: сексвигинтиллион
|
72
|
+
84: септемвигинтиллион
|
73
|
+
87: октовигинтиллион
|
74
|
+
90: новемвигинтиллион
|
75
|
+
93: тривигинтиллион
|
76
|
+
96: антригинтиллион
|
77
|
+
99: дуотригинтиллион
|
78
|
+
100: гугол
|
79
|
+
single_feminine:
|
80
|
+
1: одна
|
81
|
+
2: две
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kabal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pavel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-01 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
description: Kabal allows you to translate numbers into text.
|
28
|
+
email:
|
29
|
+
- kalashnikovisme@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".coveralls.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- kabal.gemspec
|
42
|
+
- lib/kabal.rb
|
43
|
+
- lib/kabal/languages/language.rb
|
44
|
+
- lib/kabal/languages/russian.rb
|
45
|
+
- lib/kabal/supported_languages.rb
|
46
|
+
- lib/kabal/version.rb
|
47
|
+
- test/lib/kabal_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
- yaml/languages.yml
|
50
|
+
- yaml/languages/ru.yml
|
51
|
+
homepage: ''
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.2.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Number To Text Helper
|
75
|
+
test_files:
|
76
|
+
- test/lib/kabal_test.rb
|
77
|
+
- test/test_helper.rb
|