kabal 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/kabal/languages/language.rb +4 -0
- data/lib/kabal/languages/russian.rb +12 -4
- data/lib/kabal/version.rb +1 -1
- data/test/lib/kabal/languages/russian_test.rb +11 -1
- data/yaml/languages/ru.yml +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf4b9fcfb470eb18a488ba782bdacd664767a3a
|
4
|
+
data.tar.gz: 8b6ad5bd552fdcb7cc42aff56039cac8991b85b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf141f18e9a73bb9e03dd7998ca45c6855bb3259983b3a241b3d7c2bbaab86c67471144ac9a427df5501708589b9ba1de15ef498db08ad0e1828b87ea22d586a
|
7
|
+
data.tar.gz: cdcf93b6454fe22751d380b30a02892c693457bb84a1bb5795d851c54b2ae65bd9a3e609cb5222437ef25509476b423fe01186b5882c6fe2cd2cb16b6e8c93cb
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/kalashnikovisme/kabal.svg?branch=master)](https://travis-ci.org/kalashnikovisme/kabal)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/kalashnikovisme/kabal/badge.png?branch=master)](https://coveralls.io/r/kalashnikovisme/kabal?branch=master)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/kabal.svg)](http://badge.fury.io/rb/kabal)
|
6
|
+
[![endorse](https://api.coderwall.com/kalashnikovisme/endorsecount.png)](https://coderwall.com/kalashnikovisme)
|
5
7
|
|
6
8
|
Kabal allows you to translate number into text.
|
7
9
|
|
@@ -4,7 +4,13 @@ require 'kabal/languages/russian/declinations'
|
|
4
4
|
class Kabal::Russian < Kabal::Language
|
5
5
|
def convert(number)
|
6
6
|
#FIXME find way to get min and max from yml file
|
7
|
-
raise NumberOutRangeError.message if number
|
7
|
+
raise NumberOutRangeError.message if number <= -(10 ** 102) or number >= 10 ** 102
|
8
|
+
#FIXME find better way
|
9
|
+
@number_name = nil
|
10
|
+
need_minus?(number) ? (minus + " " + natural_number_name(-number)) : natural_number_name(number)
|
11
|
+
end
|
12
|
+
|
13
|
+
def natural_number_name(number)
|
8
14
|
#FIXME switch case next lines
|
9
15
|
return single(number) if number >= 0 and number <= 19
|
10
16
|
return two_words(number) if number >= 20 and number <= 99
|
@@ -12,6 +18,10 @@ class Kabal::Russian < Kabal::Language
|
|
12
18
|
ten_powers(number) if number >= 1000
|
13
19
|
end
|
14
20
|
|
21
|
+
def need_minus?(number)
|
22
|
+
number < 0
|
23
|
+
end
|
24
|
+
|
15
25
|
def single(number)
|
16
26
|
if @feminine_name_for_thousands
|
17
27
|
@feminine_name_for_thousands = false
|
@@ -61,9 +71,7 @@ class Kabal::Russian < Kabal::Language
|
|
61
71
|
end
|
62
72
|
|
63
73
|
def less_thousands(number)
|
64
|
-
unless number == 0
|
65
|
-
@number_name += " " + three_words(number % 1000)
|
66
|
-
end
|
74
|
+
@number_name += " " + three_words(number % 1000) unless number == 0
|
67
75
|
end
|
68
76
|
|
69
77
|
def number_is_thousands?(number)
|
data/lib/kabal/version.rb
CHANGED
@@ -7,37 +7,47 @@ class RussianTest < TestCase
|
|
7
7
|
|
8
8
|
def test_to_text_with_single_number
|
9
9
|
assert_equal @rus.convert(1), "один"
|
10
|
+
assert_equal @rus.convert(-1), "минус один"
|
10
11
|
end
|
11
12
|
def test_to_text_with_two_words_number
|
12
13
|
assert_equal @rus.convert(25), "двадцать пять"
|
14
|
+
assert_equal @rus.convert(-25), "минус двадцать пять"
|
13
15
|
end
|
14
16
|
def test_to_text_with_three_words_number
|
15
17
|
assert_equal @rus.convert(625), "шестьсот двадцать пять"
|
18
|
+
assert_equal @rus.convert(-625), "минус шестьсот двадцать пять"
|
16
19
|
end
|
17
20
|
def test_to_text_with_ten_powers
|
18
21
|
assert_equal @rus.convert(125625), "сто двадцать пять тысяч шестьсот двадцать пять"
|
22
|
+
assert_equal @rus.convert(-125625), "минус сто двадцать пять тысяч шестьсот двадцать пять"
|
19
23
|
end
|
20
24
|
def test_to_text_with_ten_powers_millions
|
21
25
|
assert_equal @rus.convert(125125625), "сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
|
26
|
+
assert_equal @rus.convert(-125125625), "минус сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
|
22
27
|
end
|
23
28
|
def test_to_text_with_ten_powers_some_number
|
24
29
|
assert_equal @rus.convert(1000001), "один миллион один"
|
30
|
+
assert_equal @rus.convert(-1000001), "минус один миллион один"
|
25
31
|
end
|
26
32
|
def test_to_text_with_google
|
27
33
|
assert_equal @rus.convert(10 ** 100), "гугол"
|
34
|
+
assert_equal @rus.convert(-(10 ** 100)), "минус гугол"
|
28
35
|
end
|
29
36
|
def test_to_text_with_three_words_without_second_order
|
30
37
|
assert_equal @rus.convert(101), "сто один"
|
38
|
+
assert_equal @rus.convert(-101), "минус сто один"
|
31
39
|
end
|
32
40
|
def test_to_text_with_three_words_without_first_and_second_order
|
33
41
|
assert_equal @rus.convert(200), "двести"
|
42
|
+
assert_equal @rus.convert(-200), "минус двести"
|
34
43
|
end
|
35
44
|
def test_to_text_with_thousands
|
36
45
|
assert_equal @rus.convert(22000), "двадцать две тысячи"
|
46
|
+
assert_equal @rus.convert(-22000), "минус двадцать две тысячи"
|
37
47
|
end
|
38
48
|
def test_to_text_with_negative_number
|
39
49
|
exception = assert_raises RuntimeError do
|
40
|
-
@rus.convert -
|
50
|
+
@rus.convert -(10 ** 103)
|
41
51
|
end
|
42
52
|
assert_equal NumberOutRangeError.message, exception.message
|
43
53
|
end
|
data/yaml/languages/ru.yml
CHANGED