number_to_words_ru 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/locales/numbers.en.yml +8 -0
- data/lib/locales/numbers.ru.yml +52 -0
- data/lib/locales/plurals.rb +22 -0
- data/lib/number_to_words_ru/array_additions/helpers.rb +42 -0
- data/lib/number_to_words_ru/array_additions/validations.rb +7 -0
- data/lib/number_to_words_ru/array_additions.rb +2 -0
- data/lib/number_to_words_ru/core_ext/array.rb +5 -0
- data/lib/number_to_words_ru/core_ext/integer.rb +11 -0
- data/lib/number_to_words_ru/figures_array.rb +9 -0
- data/lib/number_to_words_ru/pluralization.rb +2 -0
- data/lib/number_to_words_ru/strategies/base.rb +10 -0
- data/lib/number_to_words_ru/strategies/en.rb +69 -0
- data/lib/number_to_words_ru/strategies/ru.rb +69 -0
- data/lib/number_to_words_ru/strategies.rb +3 -0
- data/lib/number_to_words_ru/translations_helpers/base.rb +9 -0
- data/lib/number_to_words_ru/translations_helpers/en.rb +37 -0
- data/lib/number_to_words_ru/translations_helpers/ru.rb +37 -0
- data/lib/number_to_words_ru/translations_helpers.rb +3 -0
- data/lib/number_to_words_ru.rb +25 -0
- data/spec/number_to_words_ru/array/ru_spec.rb +27 -0
- data/spec/number_to_words_ru/integer/ru_spec.rb +279 -0
- data/spec/spec_helper.rb +8 -0
- metadata +70 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
en:
|
2
|
+
numbers:
|
3
|
+
ones: [nought, one, two, three, four, five, six, seven, eight, nine]
|
4
|
+
teens: [ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen]
|
5
|
+
tens: [nought, ten, twenty, thirty, forty, fifty, sixty, seventy, nought, ninety]
|
6
|
+
union: and
|
7
|
+
hundreds: hundred
|
8
|
+
mega: [ones, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
ru:
|
2
|
+
numbers:
|
3
|
+
ones_male: [ноль, один, два, три, четыре, пять, шесть, семь, восемь, девять]
|
4
|
+
ones_female: [ноль, однa, двe, три, четыре, пять, шесть, семь, восемь, девять]
|
5
|
+
teens: [десять, одиннадцать, двенадцать, тринадцать, четырнадцать, пятнадцать, шестнадцать, семнадцать, восемнадцать, девятнадцать]
|
6
|
+
tens: [ноль, десять, двадцать, тридцать, сорок, пятьдесят, шестьдесят, семьдесят, восемьдесят, девяносто]
|
7
|
+
hundreds: [ноль, сто, двести, триста, четыреста, пятьсот, шестьсот, семьсот, восемьсот, девятьсот]
|
8
|
+
thousands:
|
9
|
+
one: тысяча
|
10
|
+
few: тысячи
|
11
|
+
many: тысяч
|
12
|
+
millions:
|
13
|
+
one: миллион
|
14
|
+
few: миллиона
|
15
|
+
many: миллионов
|
16
|
+
billions:
|
17
|
+
one: миллиард
|
18
|
+
few: миллиарда
|
19
|
+
many: миллиардов
|
20
|
+
trillions:
|
21
|
+
one: триллион
|
22
|
+
few: триллионa
|
23
|
+
many: триллионов
|
24
|
+
quadrillions:
|
25
|
+
one: квадриллион
|
26
|
+
few: квадриллиона
|
27
|
+
many: квадриллионов
|
28
|
+
quintillions:
|
29
|
+
one: квинтиллион
|
30
|
+
few: квинтиллиона
|
31
|
+
many: квинтиллионов
|
32
|
+
sextillions:
|
33
|
+
one: секстиллион
|
34
|
+
few: секстиллиона
|
35
|
+
many: секстиллионов
|
36
|
+
septillions:
|
37
|
+
one: септиллион
|
38
|
+
few: секстиллиона
|
39
|
+
many: секстиллионов
|
40
|
+
octillions:
|
41
|
+
one: октиллион
|
42
|
+
few: октиллиона
|
43
|
+
many: октиллионов
|
44
|
+
nonillions:
|
45
|
+
one: нониллион
|
46
|
+
few: нониллиона
|
47
|
+
many: нониллионов
|
48
|
+
decillions:
|
49
|
+
one: дециллион
|
50
|
+
few: дециллиона
|
51
|
+
many: дециллионов
|
52
|
+
mega: [ones, thousands, millions, billions, trillions, quadrillions, quintillion, sextillions, septillions, octillions, nonillions, decillions]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
ru_rule = lambda do |count|
|
2
|
+
case count
|
3
|
+
when Integer
|
4
|
+
case
|
5
|
+
when 1 == count
|
6
|
+
:one
|
7
|
+
when (2..4).include?(count)
|
8
|
+
:few
|
9
|
+
else
|
10
|
+
:many
|
11
|
+
end
|
12
|
+
else
|
13
|
+
:other
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
en_rule = lambda{|count| 1 == count ? :one : :other}
|
18
|
+
|
19
|
+
{
|
20
|
+
:ru => {:i18n => {:plural => {:rule => ru_rule}}},
|
21
|
+
:en => {:i18n => {:plural => {:rule => en_rule}}}
|
22
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ArrayAdditions
|
2
|
+
module Helpers
|
3
|
+
THOUSAND_CAPACITY = 1
|
4
|
+
|
5
|
+
def capacity_count
|
6
|
+
count = (self.length.to_f / 3).ceil
|
7
|
+
1 == count ? nil : count
|
8
|
+
end
|
9
|
+
|
10
|
+
def figures_array_in_capacity capacity
|
11
|
+
self[capacity * 3, 3]
|
12
|
+
end
|
13
|
+
|
14
|
+
def number_in_capacity capacity
|
15
|
+
figures_array_in_capacity(capacity).reverse.join.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_a_thousand_capacity? capacity
|
19
|
+
THOUSAND_CAPACITY == capacity
|
20
|
+
end
|
21
|
+
|
22
|
+
def ones
|
23
|
+
self[0] if 0 < self[0].to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def teens
|
27
|
+
tens_with_ones if 1 == tens
|
28
|
+
end
|
29
|
+
|
30
|
+
def tens
|
31
|
+
self[1] if self[1] and 0 < self[1].to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def tens_with_ones
|
35
|
+
[ones, tens] if ones and tens
|
36
|
+
end
|
37
|
+
|
38
|
+
def hundreds
|
39
|
+
self[2] if 0 < self[2].to_i
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Strategies
|
2
|
+
class En < Base
|
3
|
+
include TranslationsHelpers::En
|
4
|
+
|
5
|
+
attr_accessor :figures_in_previous_capacity
|
6
|
+
|
7
|
+
def convert figures
|
8
|
+
@figures = figures.reverse
|
9
|
+
|
10
|
+
@words = strings
|
11
|
+
@words.empty? ? zero : @words.reverse.join(' ')
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def strings
|
17
|
+
if figures.capacity_count
|
18
|
+
complex_to_words
|
19
|
+
elsif figures.hundreds
|
20
|
+
simple_hundreds_to_words
|
21
|
+
elsif figures.tens or figures.ones
|
22
|
+
simple_to_words
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def complex_to_words
|
29
|
+
words = []
|
30
|
+
figures.capacity_count.times do |capacity|
|
31
|
+
number_in_capacity_by_words = save_parent_figures do |parent_figures|
|
32
|
+
@figures = parent_figures.figures_array_in_capacity(capacity)
|
33
|
+
strings
|
34
|
+
end
|
35
|
+
|
36
|
+
if !number_in_capacity_by_words.empty?
|
37
|
+
words.push translation_megs(capacity) if 0 < capacity
|
38
|
+
words += number_in_capacity_by_words
|
39
|
+
end
|
40
|
+
end
|
41
|
+
words
|
42
|
+
end
|
43
|
+
|
44
|
+
def simple_hundreds_to_words
|
45
|
+
simple_to_words + [translation_hundreds(figures.hundreds)]
|
46
|
+
end
|
47
|
+
|
48
|
+
def simple_to_words
|
49
|
+
if figures.teens
|
50
|
+
[translation_teens(figures.ones)]
|
51
|
+
elsif figures.tens
|
52
|
+
figures.ones ?
|
53
|
+
[translation_tens_with_ones(figures.tens_with_ones)] :
|
54
|
+
[translation_tens(figures.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
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Strategies
|
2
|
+
class Ru < Base
|
3
|
+
include TranslationsHelpers::Ru
|
4
|
+
|
5
|
+
def convert figures
|
6
|
+
@figures = figures.reverse
|
7
|
+
@words = strings
|
8
|
+
|
9
|
+
@words.empty? ? zero : @words.reverse.join(' ')
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def strings gender = :male
|
15
|
+
if figures.capacity_count
|
16
|
+
complex_to_words
|
17
|
+
elsif figures.hundreds
|
18
|
+
simple_hundreds_to_words gender
|
19
|
+
elsif figures.tens or figures.ones
|
20
|
+
simple_to_words gender
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def complex_to_words
|
27
|
+
words = []
|
28
|
+
figures.capacity_count.times do |capacity|
|
29
|
+
number_in_capacity_by_words = save_parent_figures do
|
30
|
+
@figures = figures.figures_array_in_capacity(capacity)
|
31
|
+
strings figures.is_a_thousand_capacity?(capacity) ? :female : :male
|
32
|
+
end
|
33
|
+
|
34
|
+
if !number_in_capacity_by_words.empty?
|
35
|
+
if 0 < capacity
|
36
|
+
words.push translation_megs(capacity, figures.number_in_capacity(capacity))
|
37
|
+
end
|
38
|
+
words += number_in_capacity_by_words
|
39
|
+
end
|
40
|
+
end
|
41
|
+
words
|
42
|
+
end
|
43
|
+
|
44
|
+
def simple_hundreds_to_words gender
|
45
|
+
simple_to_words(gender) + [translation_hundreds(figures.hundreds)]
|
46
|
+
end
|
47
|
+
|
48
|
+
def simple_to_words gender
|
49
|
+
if figures.teens
|
50
|
+
[translation_teens(figures.ones)]
|
51
|
+
elsif figures.tens
|
52
|
+
figures.ones ?
|
53
|
+
[translation_tens_with_ones(figures.tens_with_ones, gender)] :
|
54
|
+
[translation_tens(figures.tens)]
|
55
|
+
elsif figures.ones
|
56
|
+
[translation_ones(figures.ones, gender)]
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_parent_figures
|
63
|
+
parent_figures = @figures
|
64
|
+
result = yield
|
65
|
+
@figures = parent_figures
|
66
|
+
result
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TranslationsHelpers::En
|
2
|
+
include TranslationsHelpers::Base
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def translation_megs capacity
|
7
|
+
t(:mega)[capacity]
|
8
|
+
end
|
9
|
+
|
10
|
+
def translation_teens number
|
11
|
+
t(:teens)[number]
|
12
|
+
end
|
13
|
+
|
14
|
+
def translation_tens number
|
15
|
+
t(:tens)[number]
|
16
|
+
end
|
17
|
+
|
18
|
+
def translation_ones number
|
19
|
+
t(:ones)[number]
|
20
|
+
end
|
21
|
+
|
22
|
+
def translation_tens_with_ones numbers
|
23
|
+
[translation_tens(numbers[1]), translation_ones(numbers[0])].join '-'
|
24
|
+
end
|
25
|
+
|
26
|
+
def translation_union
|
27
|
+
t :union
|
28
|
+
end
|
29
|
+
|
30
|
+
def translation_hundreds number
|
31
|
+
[t(:ones)[number], t(:hundreds)].join ' '
|
32
|
+
end
|
33
|
+
|
34
|
+
def zero
|
35
|
+
t(:ones_male)[0]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TranslationsHelpers::Ru
|
2
|
+
include TranslationsHelpers::Base
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def translation_megs capacity, number
|
7
|
+
t translation_mega(capacity), :count => number
|
8
|
+
end
|
9
|
+
|
10
|
+
def translation_teens number
|
11
|
+
t(:teens)[number]
|
12
|
+
end
|
13
|
+
|
14
|
+
def translation_tens number
|
15
|
+
t(:tens)[number]
|
16
|
+
end
|
17
|
+
|
18
|
+
def translation_ones number, gender
|
19
|
+
t([:ones, gender].join('_'))[number]
|
20
|
+
end
|
21
|
+
|
22
|
+
def translation_tens_with_ones numbers, gender
|
23
|
+
[translation_tens(numbers[1]), translation_ones(numbers[0], gender)].join ' '
|
24
|
+
end
|
25
|
+
|
26
|
+
def translation_hundreds number
|
27
|
+
t(:hundreds)[number]
|
28
|
+
end
|
29
|
+
|
30
|
+
def translation_mega capacity
|
31
|
+
t(:mega)[capacity]
|
32
|
+
end
|
33
|
+
|
34
|
+
def zero
|
35
|
+
t(:ones_male)[0]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'i18n'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
require 'number_to_words_ru/translations_helpers'
|
6
|
+
require 'number_to_words_ru/strategies'
|
7
|
+
require 'number_to_words_ru/array_additions'
|
8
|
+
require 'number_to_words_ru/figures_array'
|
9
|
+
|
10
|
+
require 'number_to_words_ru/core_ext/integer'
|
11
|
+
require 'number_to_words_ru/core_ext/array'
|
12
|
+
|
13
|
+
module I18nInitialization
|
14
|
+
extend self
|
15
|
+
|
16
|
+
def init
|
17
|
+
I18n.load_path << locale_files
|
18
|
+
end
|
19
|
+
|
20
|
+
def locale_files
|
21
|
+
Dir[File.join(File.dirname(__FILE__), 'locales', '**/*')]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
I18nInitialization.init
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
around :each do |example|
|
5
|
+
I18n.with_locale(:ru) do
|
6
|
+
example.run
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe 'to_words' do
|
12
|
+
context 'simple example' do
|
13
|
+
subject { [1, 2, 3] }
|
14
|
+
its(:to_words) { should == 3.times.map { |number| t(:ones_male)[number + 1] } }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'complex example' do
|
18
|
+
subject { [101, 21, 13] }
|
19
|
+
|
20
|
+
its(:to_words) { should == [
|
21
|
+
[t(:hundreds)[1], t(:ones_male)[1]].join(' '),
|
22
|
+
[t(:tens)[2], t(:ones_male)[1]].join(' '),
|
23
|
+
t(:teens)[3]
|
24
|
+
] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
around :each do |example|
|
5
|
+
I18n.with_locale(:ru) do
|
6
|
+
example.run
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#to_words' do
|
11
|
+
describe 'ones' do
|
12
|
+
context '0 as uniq example' do
|
13
|
+
subject { 0 }
|
14
|
+
its(:to_words) { should == t(:ones_male)[0] }
|
15
|
+
end
|
16
|
+
|
17
|
+
context '1 as lower example' do
|
18
|
+
subject { 1 }
|
19
|
+
its(:to_words) { should == t(:ones_male)[1] }
|
20
|
+
end
|
21
|
+
|
22
|
+
context '9 as upper example' do
|
23
|
+
subject { 9 }
|
24
|
+
its(:to_words) { should == t(:ones_male)[9] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'teens' do
|
29
|
+
context '10 as uniq example' do
|
30
|
+
subject { 10 }
|
31
|
+
its(:to_words) { should == t(:teens)[0] }
|
32
|
+
end
|
33
|
+
|
34
|
+
context '11 as lower example' do
|
35
|
+
subject { 11 }
|
36
|
+
its(:to_words) { should == t(:teens)[1] }
|
37
|
+
end
|
38
|
+
|
39
|
+
context '19 as upper example' do
|
40
|
+
subject { 19 }
|
41
|
+
its(:to_words) { should == t(:teens)[9] }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'tens' do
|
46
|
+
context '20 as lower example' do
|
47
|
+
subject { 20 }
|
48
|
+
its(:to_words) { should == t(:tens)[2] }
|
49
|
+
end
|
50
|
+
|
51
|
+
context '21 as lower example with ones' do
|
52
|
+
subject { 21 }
|
53
|
+
its(:to_words) { should == [t(:tens)[2], t(:ones_male)[1]].join(' ') }
|
54
|
+
end
|
55
|
+
|
56
|
+
context '90 as upper example' do
|
57
|
+
subject { 90 }
|
58
|
+
its(:to_words) { should == t(:tens)[9] }
|
59
|
+
end
|
60
|
+
|
61
|
+
context '99 as upper example with ones' do
|
62
|
+
subject { 99 }
|
63
|
+
its(:to_words) { should == [t(:tens)[9], t(:ones_male)[9]].join(' ') }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'hundreds' do
|
68
|
+
context '100 as lower example' do
|
69
|
+
subject { 100 }
|
70
|
+
its(:to_words) { should == t(:hundreds)[1] }
|
71
|
+
end
|
72
|
+
|
73
|
+
context '101 as lower example with ones' do
|
74
|
+
subject { 101 }
|
75
|
+
its(:to_words) { should == [t(:hundreds)[1], t(:ones_male)[1]].join(' ') }
|
76
|
+
end
|
77
|
+
|
78
|
+
context '111 as lower example with teens' do
|
79
|
+
subject { 111 }
|
80
|
+
its(:to_words) { should == [t(:hundreds)[1], t(:teens)[1]].join(' ') }
|
81
|
+
end
|
82
|
+
|
83
|
+
context '120 as lower example with tens' do
|
84
|
+
subject { 120 }
|
85
|
+
its(:to_words) { should == [t(:hundreds)[1], t(:tens)[2]].join(' ') }
|
86
|
+
end
|
87
|
+
|
88
|
+
context '121 as lower example with tens and ones' do
|
89
|
+
subject { 121 }
|
90
|
+
|
91
|
+
its(:to_words) { should == [
|
92
|
+
t(:hundreds)[1],
|
93
|
+
t(:tens)[2],
|
94
|
+
t(:ones_male)[1]
|
95
|
+
].join(' ') }
|
96
|
+
end
|
97
|
+
|
98
|
+
context '900 as upper example' do
|
99
|
+
subject { 900 }
|
100
|
+
its(:to_words) { should == t(:hundreds)[9] }
|
101
|
+
end
|
102
|
+
|
103
|
+
context '909 as upper example with ones' do
|
104
|
+
subject { 909 }
|
105
|
+
its(:to_words) { should == [t(:hundreds)[9], t(:ones_male)[9]].join(' ') }
|
106
|
+
end
|
107
|
+
|
108
|
+
context '919 as upper example with teens' do
|
109
|
+
subject { 919 }
|
110
|
+
its(:to_words) { should == [t(:hundreds)[9], t(:teens)[9]].join(' ') }
|
111
|
+
end
|
112
|
+
|
113
|
+
context '990 as upper example with tens' do
|
114
|
+
subject { 990 }
|
115
|
+
its(:to_words) { should == [t(:hundreds)[9], t(:tens)[9]].join(' ') }
|
116
|
+
end
|
117
|
+
|
118
|
+
context '999 as upper example with tens and ones' do
|
119
|
+
subject { 999 }
|
120
|
+
|
121
|
+
its(:to_words) { should == [t(:hundreds)[9], t(:tens)[9], t(:ones_male)[9]].
|
122
|
+
join(' ') }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'thousands' do
|
127
|
+
describe 'one' do
|
128
|
+
context '1000 as uniq example' do
|
129
|
+
subject { 1000 }
|
130
|
+
|
131
|
+
its(:to_words) { should == [t(:ones_female)[1], t(:thousands, :count => 1)].
|
132
|
+
join(' ') }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'few' do
|
136
|
+
context '2000 as lower example' do
|
137
|
+
subject { 2000 }
|
138
|
+
|
139
|
+
its(:to_words) { should == [t(:ones_female)[2], t(:thousands, :count => 2)].
|
140
|
+
join(' ') }
|
141
|
+
end
|
142
|
+
|
143
|
+
context '4000 as upper example' do
|
144
|
+
subject { 4000 }
|
145
|
+
|
146
|
+
its(:to_words) { should == [t(:ones_female)[4], t(:thousands, :count => 4)].
|
147
|
+
join(' ') }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'many' do
|
152
|
+
context '5000 as lower example' do
|
153
|
+
subject { 5000 }
|
154
|
+
|
155
|
+
its(:to_words) { should == [t(:ones_female)[5], t(:thousands, :count => 5)].
|
156
|
+
join(' ') }
|
157
|
+
end
|
158
|
+
|
159
|
+
context '999000 as upper example' do
|
160
|
+
subject { 999000 }
|
161
|
+
|
162
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
163
|
+
t(:tens)[9],
|
164
|
+
t(:ones_female)[9],
|
165
|
+
t(:thousands, :count => 999)
|
166
|
+
].join(' ') }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'custom' do
|
171
|
+
context '999999 as example with first capacity' do
|
172
|
+
subject { 999999 }
|
173
|
+
|
174
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
175
|
+
t(:tens)[9],
|
176
|
+
t(:ones_female)[9],
|
177
|
+
t(:thousands, :count => 999),
|
178
|
+
t(:hundreds)[9],
|
179
|
+
t(:tens)[9],
|
180
|
+
t(:ones_male)[9],
|
181
|
+
].join(' ') }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe 'millions' do
|
188
|
+
describe 'one' do
|
189
|
+
context '1000000 as uniq example' do
|
190
|
+
subject { 1000000 }
|
191
|
+
|
192
|
+
its(:to_words) { should == [t(:ones_male)[1], t(:millions, :count => 1)].
|
193
|
+
join(' ') }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'few' do
|
198
|
+
context '2000000 as lower example in few' do
|
199
|
+
subject { 2000000 }
|
200
|
+
|
201
|
+
its(:to_words) { should == [t(:ones_male)[2], t(:millions, :count => 2)].
|
202
|
+
join(' ') }
|
203
|
+
end
|
204
|
+
|
205
|
+
context '4000000 as upper example in few' do
|
206
|
+
subject { 4000000 }
|
207
|
+
|
208
|
+
its(:to_words) { should == [t(:ones_male)[4], t(:millions, :count => 4)].
|
209
|
+
join(' ') }
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'many' do
|
214
|
+
context '5000000 as lower example in many' do
|
215
|
+
subject { 5000000 }
|
216
|
+
|
217
|
+
its(:to_words) { should == [t(:ones_male)[5], t(:millions, :count => 5)].
|
218
|
+
join(' ') }
|
219
|
+
end
|
220
|
+
|
221
|
+
context '99900000 as upper example' do
|
222
|
+
subject { 999000000 }
|
223
|
+
|
224
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
225
|
+
t(:tens)[9],
|
226
|
+
t(:ones_male)[9],
|
227
|
+
t(:millions, :count => 999)
|
228
|
+
].join(' ') }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'custom' do
|
233
|
+
context '999000999 as example with first capacity' do
|
234
|
+
subject { 999000999 }
|
235
|
+
|
236
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
237
|
+
t(:tens)[9],
|
238
|
+
t(:ones_male)[9],
|
239
|
+
t(:millions, :count => 999),
|
240
|
+
t(:hundreds)[9],
|
241
|
+
t(:tens)[9],
|
242
|
+
t(:ones_male)[9],
|
243
|
+
].join(' ') }
|
244
|
+
end
|
245
|
+
|
246
|
+
context '999999000 as example with second capacity' do
|
247
|
+
subject { 999999000 }
|
248
|
+
|
249
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
250
|
+
t(:tens)[9],
|
251
|
+
t(:ones_male)[9],
|
252
|
+
t(:millions, :count => 999),
|
253
|
+
t(:hundreds)[9],
|
254
|
+
t(:tens)[9],
|
255
|
+
t(:ones_female)[9],
|
256
|
+
t(:thousands, :count => 999),
|
257
|
+
].join(' ') }
|
258
|
+
end
|
259
|
+
|
260
|
+
context '999999999 as example with first and second capacity' do
|
261
|
+
subject { 999999999 }
|
262
|
+
|
263
|
+
its(:to_words) { should == [t(:hundreds)[9],
|
264
|
+
t(:tens)[9],
|
265
|
+
t(:ones_male)[9],
|
266
|
+
t(:millions, :count => 999),
|
267
|
+
t(:hundreds)[9],
|
268
|
+
t(:tens)[9],
|
269
|
+
t(:ones_female)[9],
|
270
|
+
t(:thousands, :count => 999),
|
271
|
+
t(:hundreds)[9],
|
272
|
+
t(:tens)[9],
|
273
|
+
t(:ones_male)[9],
|
274
|
+
].join(' ') }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: number_to_words_ru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kirill Lazarev
|
9
|
+
autorequire: number_to_words_ru
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-24 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple convert number to russian words using I18N.
|
15
|
+
email: k.s.lazarev@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/locales/numbers.en.yml
|
21
|
+
- lib/locales/numbers.ru.yml
|
22
|
+
- lib/locales/plurals.rb
|
23
|
+
- lib/number_to_words_ru/array_additions/helpers.rb
|
24
|
+
- lib/number_to_words_ru/array_additions/validations.rb
|
25
|
+
- lib/number_to_words_ru/array_additions.rb
|
26
|
+
- lib/number_to_words_ru/core_ext/array.rb
|
27
|
+
- lib/number_to_words_ru/core_ext/integer.rb
|
28
|
+
- lib/number_to_words_ru/figures_array.rb
|
29
|
+
- lib/number_to_words_ru/pluralization.rb
|
30
|
+
- lib/number_to_words_ru/strategies/base.rb
|
31
|
+
- lib/number_to_words_ru/strategies/en.rb
|
32
|
+
- lib/number_to_words_ru/strategies/ru.rb
|
33
|
+
- lib/number_to_words_ru/strategies.rb
|
34
|
+
- lib/number_to_words_ru/translations_helpers/base.rb
|
35
|
+
- lib/number_to_words_ru/translations_helpers/en.rb
|
36
|
+
- lib/number_to_words_ru/translations_helpers/ru.rb
|
37
|
+
- lib/number_to_words_ru/translations_helpers.rb
|
38
|
+
- lib/number_to_words_ru.rb
|
39
|
+
- spec/number_to_words_ru/array/ru_spec.rb
|
40
|
+
- spec/number_to_words_ru/integer/ru_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: http://github.com/kslazarev/number_to_words_ru
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
hash: -3335539547606838716
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Simple convert number to russian words using I18N.
|
70
|
+
test_files: []
|