numbers_and_words 0.4.0 → 0.5.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.
- data/README.rdoc +41 -11
- data/lib/numbers_and_words/array_additions/helpers.rb +2 -2
- data/lib/numbers_and_words/core_ext.rb +1 -1
- data/lib/numbers_and_words/i18n.rb +1 -1
- data/lib/numbers_and_words/i18n/initialization.rb +7 -5
- data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +43 -0
- data/lib/numbers_and_words/i18n/locales/numbers.it.yml +7 -0
- data/lib/numbers_and_words/i18n/locales/numbers.nl.yml +7 -0
- data/lib/numbers_and_words/i18n/locales/numbers.tr.yml +1 -1
- data/lib/numbers_and_words/i18n/pluralization.rb +1 -0
- data/lib/numbers_and_words/i18n/plurals/fr.rb +15 -0
- data/lib/numbers_and_words/i18n/plurals/ru.rb +1 -1
- data/lib/numbers_and_words/strategies.rb +6 -0
- data/lib/numbers_and_words/strategies/base.rb +7 -0
- data/lib/numbers_and_words/strategies/en.rb +1 -64
- data/lib/numbers_and_words/strategies/families/base.rb +71 -0
- data/lib/numbers_and_words/strategies/families/cyrillic.rb +18 -0
- data/lib/numbers_and_words/strategies/families/latin.rb +9 -0
- data/lib/numbers_and_words/strategies/fr.rb +32 -0
- data/lib/numbers_and_words/strategies/it.rb +8 -0
- data/lib/numbers_and_words/strategies/nl.rb +23 -0
- data/lib/numbers_and_words/strategies/ru.rb +1 -64
- data/lib/numbers_and_words/strategies/tr.rb +1 -64
- data/lib/numbers_and_words/strategies/ua.rb +4 -2
- data/lib/numbers_and_words/translations_helpers.rb +7 -0
- data/lib/numbers_and_words/translations_helpers/en.rb +2 -31
- data/lib/numbers_and_words/translations_helpers/families/base.rb +30 -0
- data/lib/numbers_and_words/translations_helpers/families/cyrillic.rb +28 -0
- data/lib/numbers_and_words/translations_helpers/families/latin.rb +23 -0
- data/lib/numbers_and_words/translations_helpers/fr.rb +34 -0
- data/lib/numbers_and_words/translations_helpers/it.rb +16 -0
- data/lib/numbers_and_words/translations_helpers/nl.rb +18 -0
- data/lib/numbers_and_words/translations_helpers/ru.rb +1 -34
- data/lib/numbers_and_words/translations_helpers/tr.rb +1 -34
- data/lib/numbers_and_words/translations_helpers/ua.rb +8 -0
- data/lib/numbers_and_words/version.rb +1 -1
- metadata +22 -2
data/README.rdoc
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
-
== numbers_and_words {<img src="https://secure.travis-ci.org/kslazarev/numbers_and_words.png" />}[http://travis-ci.org/kslazarev/numbers_and_words]
|
1
|
+
== numbers_and_words {<img src="https://secure.travis-ci.org/kslazarev/numbers_and_words.png" />}[http://travis-ci.org/kslazarev/numbers_and_words] {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/kslazarev/numbers_and_words]
|
2
2
|
|
3
3
|
Convert numbers to words using the I18n library.
|
4
4
|
|
5
5
|
Перевод чисел в слова при помощи библиотеки I18n.
|
6
6
|
|
7
|
-
|
7
|
+
Converti les nombres en lettres en utilisant la librairie I18n.
|
8
|
+
|
9
|
+
== Supported Languages / Языки / Langues Supportées
|
8
10
|
|
9
11
|
* English
|
10
12
|
* Русский
|
13
|
+
* Français
|
11
14
|
* Українська
|
12
|
-
* Türkçe
|
15
|
+
* Türkçe**
|
16
|
+
* Italiano**
|
17
|
+
* Nederlands**
|
18
|
+
|
19
|
+
** Experimental
|
13
20
|
|
14
|
-
== Examples / Примеры
|
21
|
+
== Examples / Примеры / Exemples
|
15
22
|
|
16
23
|
I18n.with_locale(:en) { 42.to_words }
|
17
24
|
=> "forty-two"
|
@@ -19,60 +26,82 @@ Convert numbers to words using the I18n library.
|
|
19
26
|
I18n.with_locale(:ru) { 42.to_words }
|
20
27
|
=> "сорок два"
|
21
28
|
|
29
|
+
I18n.with_locale(:fr) { 42.to_words }
|
30
|
+
=> "quarante-deux"
|
31
|
+
|
22
32
|
21.to_words
|
23
33
|
=> "twenty-one"
|
24
34
|
=> "двадцать один"
|
35
|
+
=> "vingt et un"
|
25
36
|
=> "двадцять один"
|
26
37
|
=> "yirmi bir"
|
38
|
+
=> "ventiuno"
|
39
|
+
=> "éénentwintig"
|
27
40
|
|
28
41
|
231.to_words
|
29
42
|
=> "two hundred thirty-one"
|
30
43
|
=> "двести тридцать один"
|
44
|
+
=> "deux cent trente-trois"
|
31
45
|
=> "двiстi тридцять один"
|
32
46
|
=> "iki yüz otuz bir"
|
47
|
+
=> "2 cento trentauno"
|
48
|
+
=> "tweehonderdéénendertig"
|
33
49
|
|
34
50
|
4030.to_words
|
35
51
|
=> "four thousand thirty"
|
36
52
|
=> "четыре тысячи тридцать"
|
53
|
+
=> "quatre mille trente"
|
37
54
|
=> "чотири тисячi тридцять"
|
38
55
|
=> "dört bin otuz"
|
56
|
+
=> "quattro mille trenta"
|
57
|
+
=> "vierthousanddertig"
|
39
58
|
|
40
59
|
1000100.to_words
|
41
60
|
=> "one million one hundred"
|
42
61
|
=> "один миллион сто"
|
62
|
+
=> "un million cent"
|
43
63
|
=> "один мiльйон сто"
|
44
64
|
=> "bir milyon bir yüz"
|
65
|
+
=> "uno milione 1 cento"
|
66
|
+
=> "één miljoen honderd"
|
45
67
|
|
46
68
|
1000000000000000000000000000000000.to_words
|
47
69
|
=> "one decillion"
|
48
70
|
=> "один дециллион"
|
71
|
+
=> "un quintilliard"
|
49
72
|
=> "один децильйон"
|
50
73
|
=> "bir desilyon"
|
74
|
+
=> "uno decillion"
|
75
|
+
=> "één decillion"
|
51
76
|
|
52
77
|
[1, 2, 3].to_words
|
53
78
|
=> ["one", "two", "three"]
|
54
79
|
=> ["один", "два", "три"]
|
80
|
+
=> ["un", "deux", "trois"]
|
55
81
|
|
56
82
|
[11, 22, 133].to_words
|
57
83
|
=> ["eleven", "twenty-two", "one hundred thirty-three"]
|
58
84
|
=> ["одиннадцать", "двадцать два", "сто тридцать три"]
|
85
|
+
=> ["onze", "vingt-deux", "cent trente-trois"]
|
59
86
|
=> ["одинадцять", "двадцять два", "сто тридцять три"]
|
60
87
|
=> ["on bir", "yirmi iki", "bir yüz otuz üç"]
|
88
|
+
=> ["undici", "ventidue", "1 cento trentatre"]
|
89
|
+
=> ["elf", "tweeentwintig", "honderddrieendertig"]
|
61
90
|
|
62
|
-
== Requirements / Требования
|
91
|
+
== Requirements / Требования / Configuration Requise
|
63
92
|
|
64
|
-
* 1.8.7 <= Ruby (compatible with/совместимость
|
65
|
-
* 0.5.0 <= I18n (earlier versions not tested/ранние версии не
|
93
|
+
* 1.8.7 <= Ruby (compatible with/совместимость с/compatible avec Ruby 1.9, JRuby and/и/et Rubinius);
|
94
|
+
* 0.5.0 <= I18n (earlier versions not tested/ранние версии не тестировались/versions précédentes non testées);
|
66
95
|
|
67
|
-
== Installation / Установка
|
96
|
+
== Installation / Установка / Installation
|
68
97
|
|
69
98
|
gem install numbers_and_words
|
70
99
|
|
71
|
-
== License / Лицензия
|
100
|
+
== License / Лицензия / Licence
|
72
101
|
|
73
102
|
MIT License
|
74
103
|
|
75
|
-
== Bugs and Language Support / Поправки и Новые Языки
|
104
|
+
== Bugs and Language Support / Поправки и Новые Языки / Bugs et Support d'autres Langues
|
76
105
|
|
77
106
|
See CHANGELOG.md for last changes.
|
78
107
|
|
@@ -80,8 +109,9 @@ Fork the project. Make your feature addition or bug fix with tests.
|
|
80
109
|
|
81
110
|
Send a pull request. Bonus points for topic branches.
|
82
111
|
|
83
|
-
== Contacts / Контакты
|
112
|
+
== Contacts / Контакты / Contacts
|
84
113
|
|
85
114
|
* Kirill Lazarev (mailto:k.s.lazarev@gmail.com)
|
86
115
|
* Daniel Doubrovkine (link:http://github.com/dblock)
|
87
116
|
* Sergey Shkirando (mailto:shkirando.s@yandex.ru)
|
117
|
+
* Ulrich Sossou (Github[http://github.com/sorich87], {Personal Page}[http://ulrichsossou.com/])
|
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'numbers_and_words/core_ext/integer'
|
2
|
-
require 'numbers_and_words/core_ext/array'
|
2
|
+
require 'numbers_and_words/core_ext/array'
|
@@ -3,20 +3,22 @@ module NumbersAndWords
|
|
3
3
|
module Initialization
|
4
4
|
extend self
|
5
5
|
|
6
|
+
attr_accessor :languages
|
7
|
+
|
6
8
|
def init
|
7
9
|
locale_files.each { |locale_file| ::I18n.load_path << locale_file}
|
8
10
|
NumbersAndWords::I18n::Pluralization.init
|
9
11
|
end
|
10
12
|
|
13
|
+
def languages
|
14
|
+
@languages ||= (locale_files.map{|path| path.split(/[\/.]/)[-2]})
|
15
|
+
end
|
16
|
+
|
11
17
|
private
|
12
18
|
|
13
19
|
def locale_files
|
14
20
|
I18n.files 'locales', '*.*'
|
15
21
|
end
|
16
|
-
|
17
|
-
def languages
|
18
|
-
locale_files.map{|path| path.split /[\/.]/}[-2]
|
19
|
-
end
|
20
22
|
end
|
21
23
|
end
|
22
|
-
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
fr:
|
2
|
+
numbers:
|
3
|
+
ones: [zéro, un, deux, trois, quatre, cinq, six, sept, huit, neuf]
|
4
|
+
teens: [dix, onze, douze, treize, quatorze, quinze, seize, dix-sept, dix-huit, dix-neuf]
|
5
|
+
tens: [zéro, dix, vingt, trente, quarante, cinquante, soixante, soixante-dix, quatre-vingt, quatre-vingt-dix]
|
6
|
+
mega: [ones, thousands, millions, billions, trillions, quadrillions, quintillion, sextillions, septillions, octillions, nonillions, decillions]
|
7
|
+
eighty: quatre-vingts
|
8
|
+
hundreds:
|
9
|
+
one: cent
|
10
|
+
many: cents
|
11
|
+
thousands:
|
12
|
+
one: mille
|
13
|
+
many: mille
|
14
|
+
millions:
|
15
|
+
one: million
|
16
|
+
many: millions
|
17
|
+
billions:
|
18
|
+
one: milliard
|
19
|
+
many: milliards
|
20
|
+
trillions:
|
21
|
+
one: billion
|
22
|
+
many: billions
|
23
|
+
quadrillions:
|
24
|
+
one: billiard
|
25
|
+
many: billiards
|
26
|
+
quintillions:
|
27
|
+
one: trillion
|
28
|
+
many: trillions
|
29
|
+
sextillions:
|
30
|
+
one: trilliard
|
31
|
+
many: trilliards
|
32
|
+
septillions:
|
33
|
+
one: quadrillion
|
34
|
+
many: quadrillions
|
35
|
+
octillions:
|
36
|
+
one: quadrilliard
|
37
|
+
many: quadrilliards
|
38
|
+
nonillions:
|
39
|
+
one: quintillion
|
40
|
+
many: quintillions
|
41
|
+
decillions:
|
42
|
+
one: quintilliard
|
43
|
+
many: quintilliards
|
@@ -0,0 +1,7 @@
|
|
1
|
+
it:
|
2
|
+
numbers:
|
3
|
+
ones: [zero, uno, due, tre, quattro, cinque, sei, sette, otto, nove]
|
4
|
+
teens: [dieci, undici, dodici, tredici, quattordici, quindici, sedici, diciasette, diciotto, diciannove]
|
5
|
+
tens: [zero, dieci, venti, trenta, quaranta, cinquanta, sessanta, settanta, ottanta, novanta]
|
6
|
+
hundreds: cento
|
7
|
+
mega: [ones, mille, milione, miliardo, triliardo, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion]
|
@@ -0,0 +1,7 @@
|
|
1
|
+
nl:
|
2
|
+
numbers:
|
3
|
+
ones: [nul, één, twee, drie, vier, vijf, zes, zeven, acht, negen]
|
4
|
+
teens: [tien, elf, twaalf, dertien, veertien, vijftien, zestien, zeventien, achttien, negentien]
|
5
|
+
tens: [nul, tien, twintig, dertig, veertig, vijftig, zestig, zeventig, tachtig, negentig]
|
6
|
+
hundreds: honderd
|
7
|
+
mega: [degenen, duizend, miljoen, miljard, biljoen, biljard, triljoen, triljard, septiljoen, octillion, noniljoen, decillion]
|
@@ -4,4 +4,4 @@ tr:
|
|
4
4
|
teens: ['on', on bir, on iki, on üç, on dört, on beş, on altı, on yedi, on sekiz, on dokuz]
|
5
5
|
tens: [sıfır, 'on', yirmi, otuz, kırk, elli, altmış, yetmiş, seksen, doksan]
|
6
6
|
hundreds: yüz
|
7
|
-
mega: [bir, bin, milyon, milyar, trilyon, katrilyon, kentilyon, seksilyon, septilyon, oktilyon, nonilyon, desilyon]
|
7
|
+
mega: [bir, bin, milyon, milyar, trilyon, katrilyon, kentilyon, seksilyon, septilyon, oktilyon, nonilyon, desilyon]
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'numbers_and_words/strategies/base'
|
2
|
+
require 'numbers_and_words/strategies/families/base'
|
3
|
+
require 'numbers_and_words/strategies/families/cyrillic'
|
4
|
+
require 'numbers_and_words/strategies/families/latin'
|
2
5
|
require 'numbers_and_words/strategies/ru'
|
3
6
|
require 'numbers_and_words/strategies/en'
|
4
7
|
require 'numbers_and_words/strategies/ua'
|
5
8
|
require 'numbers_and_words/strategies/tr'
|
9
|
+
require 'numbers_and_words/strategies/fr'
|
10
|
+
require 'numbers_and_words/strategies/nl'
|
11
|
+
require 'numbers_and_words/strategies/it'
|
@@ -6,6 +6,13 @@ module NumbersAndWords
|
|
6
6
|
def self.factory
|
7
7
|
"NumbersAndWords::Strategies::#{::I18n.locale.to_s.titleize}".constantize.new
|
8
8
|
end
|
9
|
+
|
10
|
+
def convert figures
|
11
|
+
@figures = figures.reverse
|
12
|
+
@words = strings
|
13
|
+
|
14
|
+
@words.empty? ? zero : @words.reverse.join(' ')
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
@@ -1,71 +1,8 @@
|
|
1
1
|
module NumbersAndWords
|
2
2
|
module Strategies
|
3
3
|
class En < Base
|
4
|
+
include Families::Latin
|
4
5
|
include NumbersAndWords::TranslationsHelpers::En
|
5
|
-
|
6
|
-
attr_accessor :figures_in_previous_capacity
|
7
|
-
|
8
|
-
def convert figures
|
9
|
-
@figures = figures.reverse
|
10
|
-
|
11
|
-
@words = strings
|
12
|
-
@words.empty? ? zero : @words.reverse.join(' ')
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def strings
|
18
|
-
if figures.capacity_count
|
19
|
-
complex_to_words
|
20
|
-
elsif figures.hundreds
|
21
|
-
simple_hundreds_to_words
|
22
|
-
elsif figures.tens or figures.ones
|
23
|
-
simple_to_words
|
24
|
-
else
|
25
|
-
[]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def complex_to_words
|
30
|
-
words = []
|
31
|
-
figures.capacity_count.times do |capacity|
|
32
|
-
number_in_capacity_by_words = save_parent_figures do |parent_figures|
|
33
|
-
@figures = parent_figures.figures_array_in_capacity(capacity)
|
34
|
-
strings
|
35
|
-
end
|
36
|
-
|
37
|
-
unless number_in_capacity_by_words.empty?
|
38
|
-
words.push translation_megs(capacity) if 0 < capacity
|
39
|
-
words += number_in_capacity_by_words
|
40
|
-
end
|
41
|
-
end
|
42
|
-
words
|
43
|
-
end
|
44
|
-
|
45
|
-
def simple_hundreds_to_words
|
46
|
-
simple_to_words + [translation_hundreds(figures.hundreds)]
|
47
|
-
end
|
48
|
-
|
49
|
-
def simple_to_words
|
50
|
-
if figures.teens
|
51
|
-
[translation_teens(figures.ones)]
|
52
|
-
elsif figures.tens
|
53
|
-
figures.ones ?
|
54
|
-
[translation_tens_with_ones(figures.tens_with_ones)] :
|
55
|
-
[translation_tens(figures.tens)]
|
56
|
-
elsif figures.ones
|
57
|
-
[translation_ones(figures.ones)]
|
58
|
-
else
|
59
|
-
[]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def save_parent_figures
|
64
|
-
parent_figures = @figures
|
65
|
-
result = yield(parent_figures)
|
66
|
-
@figures = parent_figures
|
67
|
-
result
|
68
|
-
end
|
69
6
|
end
|
70
7
|
end
|
71
8
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module Families
|
4
|
+
module Base
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def strings
|
9
|
+
if figures.capacity_count
|
10
|
+
number_without_capacity_to_words + complex_number_to_words
|
11
|
+
elsif figures.hundreds
|
12
|
+
hundreds_number_to_words
|
13
|
+
elsif figures.tens or figures.ones
|
14
|
+
simple_number_to_words
|
15
|
+
else
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def complex_number_to_words
|
21
|
+
(1..figures.capacity_count).map{|capacity| capacity_iteration(capacity)}.flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
def capacity_iteration capacity
|
25
|
+
words = []
|
26
|
+
capacity_words = words_in_capacity(capacity)
|
27
|
+
words.push(translation_megs(capacity)) unless capacity_words.empty?
|
28
|
+
words + capacity_words
|
29
|
+
end
|
30
|
+
|
31
|
+
def words_in_capacity capacity = 0
|
32
|
+
save_parent_figures do |parent_figures|
|
33
|
+
@figures = parent_figures.figures_array_in_capacity(capacity)
|
34
|
+
strings
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :number_without_capacity_to_words, :words_in_capacity
|
39
|
+
|
40
|
+
def hundreds_number_to_words
|
41
|
+
simple_number_to_words + [translation_hundreds(figures.hundreds)]
|
42
|
+
end
|
43
|
+
|
44
|
+
def complex_tens
|
45
|
+
figures.ones ?
|
46
|
+
translation_tens_with_ones(figures.tens_with_ones) :
|
47
|
+
translation_tens(figures.tens)
|
48
|
+
end
|
49
|
+
|
50
|
+
def simple_number_to_words
|
51
|
+
if figures.teens
|
52
|
+
[translation_teens(figures.ones)]
|
53
|
+
elsif figures.tens
|
54
|
+
[complex_tens]
|
55
|
+
elsif figures.ones
|
56
|
+
[translation_ones(figures.ones)]
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_parent_figures
|
63
|
+
parent_figures = @figures
|
64
|
+
result = yield(parent_figures)
|
65
|
+
@figures = parent_figures
|
66
|
+
result
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module Families
|
4
|
+
module Cyrillic
|
5
|
+
include NumbersAndWords::Strategies::Families::Base
|
6
|
+
|
7
|
+
attr_accessor :current_capacity
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def words_in_capacity capacity = 0
|
12
|
+
@current_capacity = capacity
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
class Fr < Base
|
4
|
+
include Families::Latin
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Fr
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def capacity_iteration capacity
|
10
|
+
words = []
|
11
|
+
capacity_words = words_in_capacity(capacity)
|
12
|
+
words.push(translation_megs(capacity)) unless capacity_words.empty?
|
13
|
+
words += capacity_words unless is_a_thousand?(capacity) and is_a_one?(capacity_words)
|
14
|
+
words
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_a_one? capacity_words
|
18
|
+
[t(:ones)[1]] == capacity_words
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_a_thousand? capacity
|
22
|
+
FiguresArray::THOUSAND_CAPACITY == capacity
|
23
|
+
end
|
24
|
+
|
25
|
+
def hundreds_number_to_words
|
26
|
+
simple_number_to_words + [
|
27
|
+
translation_hundreds(figures.hundreds, simple_number_to_words.empty?)
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
class Nl < Base
|
4
|
+
include Families::Latin
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Nl
|
6
|
+
|
7
|
+
def hundreds_number_to_words
|
8
|
+
[super.reverse.join]
|
9
|
+
end
|
10
|
+
|
11
|
+
def capacity_iteration capacity
|
12
|
+
if FiguresArray::THOUSAND_CAPACITY == capacity
|
13
|
+
words = []
|
14
|
+
capacity_words = words_in_capacity(capacity)
|
15
|
+
words.push(translation_megs(capacity)) unless capacity_words.empty?
|
16
|
+
capacity_words.empty? ? [] : [capacity_words, words].join
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,71 +1,8 @@
|
|
1
1
|
module NumbersAndWords
|
2
2
|
module Strategies
|
3
3
|
class Ru < Base
|
4
|
+
include Families::Cyrillic
|
4
5
|
include NumbersAndWords::TranslationsHelpers::Ru
|
5
|
-
|
6
|
-
def convert figures
|
7
|
-
@figures = figures.reverse
|
8
|
-
@words = strings
|
9
|
-
|
10
|
-
@words.empty? ? zero : @words.reverse.join(' ')
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def strings gender = :male
|
16
|
-
if figures.capacity_count
|
17
|
-
complex_to_words
|
18
|
-
elsif figures.hundreds
|
19
|
-
simple_hundreds_to_words gender
|
20
|
-
elsif figures.tens or figures.ones
|
21
|
-
simple_to_words gender
|
22
|
-
else
|
23
|
-
[]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def complex_to_words
|
28
|
-
words = []
|
29
|
-
figures.capacity_count.times do |capacity|
|
30
|
-
number_in_capacity_by_words = save_parent_figures do
|
31
|
-
@figures = figures.figures_array_in_capacity(capacity)
|
32
|
-
strings figures.is_a_thousand_capacity?(capacity) ? :female : :male
|
33
|
-
end
|
34
|
-
|
35
|
-
unless number_in_capacity_by_words.empty?
|
36
|
-
if 0 < capacity
|
37
|
-
words.push translation_megs(capacity, figures.number_in_capacity(capacity))
|
38
|
-
end
|
39
|
-
words += number_in_capacity_by_words
|
40
|
-
end
|
41
|
-
end
|
42
|
-
words
|
43
|
-
end
|
44
|
-
|
45
|
-
def simple_hundreds_to_words gender
|
46
|
-
simple_to_words(gender) + [translation_hundreds(figures.hundreds)]
|
47
|
-
end
|
48
|
-
|
49
|
-
def simple_to_words gender
|
50
|
-
if figures.teens
|
51
|
-
[translation_teens(figures.ones)]
|
52
|
-
elsif figures.tens
|
53
|
-
figures.ones ?
|
54
|
-
[translation_tens_with_ones(figures.tens_with_ones, gender)] :
|
55
|
-
[translation_tens(figures.tens)]
|
56
|
-
elsif figures.ones
|
57
|
-
[translation_ones(figures.ones, gender)]
|
58
|
-
else
|
59
|
-
[]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def save_parent_figures
|
64
|
-
parent_figures = @figures
|
65
|
-
result = yield
|
66
|
-
@figures = parent_figures
|
67
|
-
result
|
68
|
-
end
|
69
6
|
end
|
70
7
|
end
|
71
8
|
end
|
@@ -1,71 +1,8 @@
|
|
1
1
|
module NumbersAndWords
|
2
2
|
module Strategies
|
3
3
|
class Tr < Base
|
4
|
+
include Families::Latin
|
4
5
|
include NumbersAndWords::TranslationsHelpers::Tr
|
5
|
-
|
6
|
-
attr_accessor :figures_in_previous_capacity
|
7
|
-
|
8
|
-
def convert figures
|
9
|
-
@figures = figures.reverse
|
10
|
-
|
11
|
-
@words = strings
|
12
|
-
@words.empty? ? zero : @words.reverse.join(' ')
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def strings
|
18
|
-
if figures.capacity_count
|
19
|
-
complex_to_words
|
20
|
-
elsif figures.hundreds
|
21
|
-
simple_hundreds_to_words
|
22
|
-
elsif figures.tens or figures.ones
|
23
|
-
simple_to_words
|
24
|
-
else
|
25
|
-
[]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def complex_to_words
|
30
|
-
words = []
|
31
|
-
figures.capacity_count.times do |capacity|
|
32
|
-
number_in_capacity_by_words = save_parent_figures do |parent_figures|
|
33
|
-
@figures = parent_figures.figures_array_in_capacity(capacity)
|
34
|
-
strings
|
35
|
-
end
|
36
|
-
|
37
|
-
unless number_in_capacity_by_words.empty?
|
38
|
-
words.push translation_megs(capacity) if 0 < capacity
|
39
|
-
words += number_in_capacity_by_words
|
40
|
-
end
|
41
|
-
end
|
42
|
-
words
|
43
|
-
end
|
44
|
-
|
45
|
-
def simple_hundreds_to_words
|
46
|
-
simple_to_words + [translation_hundreds(figures.hundreds)]
|
47
|
-
end
|
48
|
-
|
49
|
-
def simple_to_words
|
50
|
-
if figures.teens
|
51
|
-
[translation_teens(figures.ones)]
|
52
|
-
elsif figures.tens
|
53
|
-
figures.ones ?
|
54
|
-
[translation_tens_with_ones(figures.tens_with_ones)] :
|
55
|
-
[translation_tens(figures.tens)]
|
56
|
-
elsif figures.ones
|
57
|
-
[translation_ones(figures.ones)]
|
58
|
-
else
|
59
|
-
[]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def save_parent_figures
|
64
|
-
parent_figures = @figures
|
65
|
-
result = yield(parent_figures)
|
66
|
-
@figures = parent_figures
|
67
|
-
result
|
68
|
-
end
|
69
6
|
end
|
70
7
|
end
|
71
8
|
end
|
@@ -1,4 +1,11 @@
|
|
1
1
|
require 'numbers_and_words/translations_helpers/base'
|
2
|
+
require 'numbers_and_words/translations_helpers/families/base'
|
3
|
+
require 'numbers_and_words/translations_helpers/families/cyrillic'
|
4
|
+
require 'numbers_and_words/translations_helpers/families/latin'
|
2
5
|
require 'numbers_and_words/translations_helpers/ru'
|
3
6
|
require 'numbers_and_words/translations_helpers/en'
|
7
|
+
require 'numbers_and_words/translations_helpers/ua'
|
4
8
|
require 'numbers_and_words/translations_helpers/tr'
|
9
|
+
require 'numbers_and_words/translations_helpers/fr'
|
10
|
+
require 'numbers_and_words/translations_helpers/nl'
|
11
|
+
require 'numbers_and_words/translations_helpers/it'
|
@@ -2,39 +2,10 @@ module NumbersAndWords
|
|
2
2
|
module TranslationsHelpers
|
3
3
|
module En
|
4
4
|
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def translation_teens number
|
9
|
-
t(:teens)[number]
|
10
|
-
end
|
11
|
-
|
12
|
-
def translation_tens number
|
13
|
-
t(:tens)[number]
|
14
|
-
end
|
15
|
-
|
16
|
-
def translation_ones number
|
17
|
-
t(:ones)[number]
|
18
|
-
end
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Latin
|
19
6
|
|
20
7
|
def translation_tens_with_ones numbers
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def translation_union
|
25
|
-
t :union
|
26
|
-
end
|
27
|
-
|
28
|
-
def translation_hundreds number
|
29
|
-
[t(:ones)[number], t(:hundreds)].join ' '
|
30
|
-
end
|
31
|
-
|
32
|
-
def translation_megs capacity
|
33
|
-
t(:mega)[capacity]
|
34
|
-
end
|
35
|
-
|
36
|
-
def zero
|
37
|
-
t(:ones)[0]
|
8
|
+
super numbers, '-'
|
38
9
|
end
|
39
10
|
end
|
40
11
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module Families
|
4
|
+
module Base
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def translation_teens number
|
9
|
+
t(:teens)[number]
|
10
|
+
end
|
11
|
+
|
12
|
+
def translation_tens number
|
13
|
+
t(:tens)[number]
|
14
|
+
end
|
15
|
+
|
16
|
+
def translation_tens_with_ones numbers, separator = ' '
|
17
|
+
[translation_tens(numbers[1]), translation_ones(numbers[0])].join separator
|
18
|
+
end
|
19
|
+
|
20
|
+
def translation_megs capacity, number = nil
|
21
|
+
number ? t(translation_mega(capacity), :count => number) : t(:mega)[capacity]
|
22
|
+
end
|
23
|
+
|
24
|
+
def translation_mega capacity
|
25
|
+
t(:mega)[capacity]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module Families
|
4
|
+
module Cyrillic
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Base
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def translation_ones number
|
10
|
+
gender = figures.is_a_thousand_capacity?(current_capacity) ? :female : :male
|
11
|
+
t([:ones, gender].join('_'))[number]
|
12
|
+
end
|
13
|
+
|
14
|
+
def translation_hundreds number
|
15
|
+
t(:hundreds)[number]
|
16
|
+
end
|
17
|
+
|
18
|
+
def translation_megs capacity
|
19
|
+
super(capacity, figures.number_in_capacity(capacity))
|
20
|
+
end
|
21
|
+
|
22
|
+
def zero
|
23
|
+
t(:ones_male)[0]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module Families
|
4
|
+
module Latin
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Base
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def translation_ones number
|
10
|
+
t(:ones)[number]
|
11
|
+
end
|
12
|
+
|
13
|
+
def translation_hundreds number
|
14
|
+
[t(:ones)[number], t(:hundreds)].join ' '
|
15
|
+
end
|
16
|
+
|
17
|
+
def zero
|
18
|
+
t(:ones)[0]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module Fr
|
4
|
+
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Latin
|
6
|
+
|
7
|
+
SPECIAL_TENS_CASE = 8
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def translation_tens number, alone = true
|
12
|
+
(SPECIAL_TENS_CASE == number and alone) ? t(:eighty) : super(number)
|
13
|
+
end
|
14
|
+
|
15
|
+
def translation_tens_with_ones numbers
|
16
|
+
if [7, 9].include? numbers[1]
|
17
|
+
[translation_tens(numbers[1] - 1, false), translation_teens(numbers[0])].join '-'
|
18
|
+
else
|
19
|
+
union = numbers[0] == 1 ? ' et ' : '-'
|
20
|
+
[translation_tens(numbers[1], false), translation_ones(numbers[0])].join union
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def translation_hundreds number, pluralize = false
|
25
|
+
hundreds = t(:hundreds, :count => pluralize ? number : 1)
|
26
|
+
(number == 1) ? hundreds : [t(:ones)[number], hundreds].join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def translation_megs capacity
|
30
|
+
super(capacity, figures.number_in_capacity(capacity))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module It
|
4
|
+
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Latin
|
6
|
+
|
7
|
+
def translation_tens_with_ones numbers
|
8
|
+
super numbers, ''
|
9
|
+
end
|
10
|
+
|
11
|
+
def translation_hundreds number
|
12
|
+
[[number], t(:hundreds)].join ' '
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module TranslationsHelpers
|
3
|
+
module Nl
|
4
|
+
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Latin
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def translation_tens_with_ones numbers
|
10
|
+
[translation_ones(numbers[0]), translation_tens(numbers[1])].join 'en'
|
11
|
+
end
|
12
|
+
|
13
|
+
def translation_hundreds number
|
14
|
+
1 == number ? t(:hundreds) : [t(:ones)[number], t(:hundreds)].join
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,40 +2,7 @@ module NumbersAndWords
|
|
2
2
|
module TranslationsHelpers
|
3
3
|
module Ru
|
4
4
|
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def translation_megs capacity, number
|
9
|
-
t translation_mega(capacity), :count => number
|
10
|
-
end
|
11
|
-
|
12
|
-
def translation_teens number
|
13
|
-
t(:teens)[number]
|
14
|
-
end
|
15
|
-
|
16
|
-
def translation_tens number
|
17
|
-
t(:tens)[number]
|
18
|
-
end
|
19
|
-
|
20
|
-
def translation_ones number, gender
|
21
|
-
t([:ones, gender].join('_'))[number]
|
22
|
-
end
|
23
|
-
|
24
|
-
def translation_tens_with_ones numbers, gender
|
25
|
-
[translation_tens(numbers[1]), translation_ones(numbers[0], gender)].join ' '
|
26
|
-
end
|
27
|
-
|
28
|
-
def translation_hundreds number
|
29
|
-
t(:hundreds)[number]
|
30
|
-
end
|
31
|
-
|
32
|
-
def translation_mega capacity
|
33
|
-
t(:mega)[capacity]
|
34
|
-
end
|
35
|
-
|
36
|
-
def zero
|
37
|
-
t(:ones_male)[0]
|
38
|
-
end
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Cyrillic
|
39
6
|
end
|
40
7
|
end
|
41
8
|
end
|
@@ -2,40 +2,7 @@ module NumbersAndWords
|
|
2
2
|
module TranslationsHelpers
|
3
3
|
module Tr
|
4
4
|
include NumbersAndWords::TranslationsHelpers::Base
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def translation_teens number
|
9
|
-
t(:teens)[number]
|
10
|
-
end
|
11
|
-
|
12
|
-
def translation_tens number
|
13
|
-
t(:tens)[number]
|
14
|
-
end
|
15
|
-
|
16
|
-
def translation_ones number
|
17
|
-
t(:ones)[number]
|
18
|
-
end
|
19
|
-
|
20
|
-
def translation_tens_with_ones numbers
|
21
|
-
[translation_tens(numbers[1]), translation_ones(numbers[0])].join ' '
|
22
|
-
end
|
23
|
-
|
24
|
-
def translation_union
|
25
|
-
t :union
|
26
|
-
end
|
27
|
-
|
28
|
-
def translation_hundreds number
|
29
|
-
[t(:ones)[number], t(:hundreds)].join ' '
|
30
|
-
end
|
31
|
-
|
32
|
-
def translation_megs capacity
|
33
|
-
t(:mega)[capacity]
|
34
|
-
end
|
35
|
-
|
36
|
-
def zero
|
37
|
-
t(:ones)[0]
|
38
|
-
end
|
5
|
+
include NumbersAndWords::TranslationsHelpers::Families::Latin
|
39
6
|
end
|
40
7
|
end
|
41
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numbers_and_words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -94,24 +94,41 @@ files:
|
|
94
94
|
- lib/numbers_and_words/i18n.rb
|
95
95
|
- lib/numbers_and_words/i18n/initialization.rb
|
96
96
|
- lib/numbers_and_words/i18n/locales/numbers.en.yml
|
97
|
+
- lib/numbers_and_words/i18n/locales/numbers.fr.yml
|
98
|
+
- lib/numbers_and_words/i18n/locales/numbers.it.yml
|
99
|
+
- lib/numbers_and_words/i18n/locales/numbers.nl.yml
|
97
100
|
- lib/numbers_and_words/i18n/locales/numbers.ru.yml
|
98
101
|
- lib/numbers_and_words/i18n/locales/numbers.tr.yml
|
99
102
|
- lib/numbers_and_words/i18n/locales/numbers.ua.yml
|
100
103
|
- lib/numbers_and_words/i18n/pluralization.rb
|
104
|
+
- lib/numbers_and_words/i18n/plurals/fr.rb
|
101
105
|
- lib/numbers_and_words/i18n/plurals/plurals.rb
|
102
106
|
- lib/numbers_and_words/i18n/plurals/ru.rb
|
103
107
|
- lib/numbers_and_words/i18n/plurals/ua.rb
|
104
108
|
- lib/numbers_and_words/strategies.rb
|
105
109
|
- lib/numbers_and_words/strategies/base.rb
|
106
110
|
- lib/numbers_and_words/strategies/en.rb
|
111
|
+
- lib/numbers_and_words/strategies/families/base.rb
|
112
|
+
- lib/numbers_and_words/strategies/families/cyrillic.rb
|
113
|
+
- lib/numbers_and_words/strategies/families/latin.rb
|
114
|
+
- lib/numbers_and_words/strategies/fr.rb
|
115
|
+
- lib/numbers_and_words/strategies/it.rb
|
116
|
+
- lib/numbers_and_words/strategies/nl.rb
|
107
117
|
- lib/numbers_and_words/strategies/ru.rb
|
108
118
|
- lib/numbers_and_words/strategies/tr.rb
|
109
119
|
- lib/numbers_and_words/strategies/ua.rb
|
110
120
|
- lib/numbers_and_words/translations_helpers.rb
|
111
121
|
- lib/numbers_and_words/translations_helpers/base.rb
|
112
122
|
- lib/numbers_and_words/translations_helpers/en.rb
|
123
|
+
- lib/numbers_and_words/translations_helpers/families/base.rb
|
124
|
+
- lib/numbers_and_words/translations_helpers/families/cyrillic.rb
|
125
|
+
- lib/numbers_and_words/translations_helpers/families/latin.rb
|
126
|
+
- lib/numbers_and_words/translations_helpers/fr.rb
|
127
|
+
- lib/numbers_and_words/translations_helpers/it.rb
|
128
|
+
- lib/numbers_and_words/translations_helpers/nl.rb
|
113
129
|
- lib/numbers_and_words/translations_helpers/ru.rb
|
114
130
|
- lib/numbers_and_words/translations_helpers/tr.rb
|
131
|
+
- lib/numbers_and_words/translations_helpers/ua.rb
|
115
132
|
- lib/numbers_and_words/version.rb
|
116
133
|
- LICENSE.txt
|
117
134
|
- README.rdoc
|
@@ -128,6 +145,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
145
|
- - ! '>='
|
129
146
|
- !ruby/object:Gem::Version
|
130
147
|
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: 4516807369747815083
|
131
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
152
|
none: false
|
133
153
|
requirements:
|