skanev-bulgarianize 0.1.1 → 0.1.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.
- data/VERSION +1 -1
- data/bulgarianize.gemspec +1 -1
- data/lib/bulgarianize/number_to_words.rb +2 -2
- data/spec/number_to_words_spec.rb +72 -65
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bulgarianize.gemspec
CHANGED
@@ -18,11 +18,11 @@ module Bulgarianize
|
|
18
18
|
HUNDREDS = %w[сто двеста триста четиристотин петстотин шестстотин седемстотин осемстотин деветстотин]
|
19
19
|
|
20
20
|
def as_words(gender = :neuter)
|
21
|
-
words_for(self.numeric, gender)
|
21
|
+
words_for(self.numeric.to_i, gender)
|
22
22
|
end
|
23
23
|
|
24
24
|
def as_leva
|
25
|
-
levas, cents = self.numeric.floor, self.numeric.%(1).*(100).to_i
|
25
|
+
levas, cents = self.numeric.floor.to_i, self.numeric.%(1).*(100).to_i
|
26
26
|
"#{words_for(levas, :male)} лева и #{cents} стотинки"
|
27
27
|
end
|
28
28
|
|
@@ -3,90 +3,97 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
require 'bigdecimal'
|
4
4
|
|
5
5
|
describe "NumberToWords" do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
describe "#as_leva" do
|
7
|
+
it "should work with simple numbers less than 10" do
|
8
|
+
%w{нула едно две три четири пет шест седем осем девет}.each_with_index do |words, number|
|
9
|
+
number.bg.as_words.should == words
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
it "should enable genders with numbers less than 10" do
|
14
|
+
numbers = [
|
15
|
+
%w{нула нула нула},
|
16
|
+
%w{един една едно},
|
17
|
+
%w{два две две},
|
18
|
+
%w{три три три},
|
19
|
+
]
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
numbers.each_with_index do |names, number|
|
22
|
+
[:male, :female, :neuter].zip(names) do |gender, name|
|
23
|
+
number.bg.as_words(gender).should == name
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
it "should work with numbers 11-19" do
|
29
|
+
%w[единадесет дванадесет тринадесет четиринадесет петданесет шестнадесет седемнадесет осемнадесет деветнадесет].zip((11..19).to_a).each do |name, number|
|
30
|
+
number.bg.as_words.should == name
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
it "should work with numbers dividable by 10" do
|
35
|
+
%w[десет двадесет тридесет четиридесет петдесет шестдесет седемдесет осемдесет деветдесет].zip([10, 20, 30, 40, 50, 60, 70, 80, 90]).each do |name, number|
|
36
|
+
number.bg.as_words.should == name
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
it "should work with numbers less than 100, not dividable by 10" do
|
41
|
+
42.bg.as_words.should == 'четиридесет и две'
|
42
|
+
97.bg.as_words.should == 'деветдесет и седем'
|
43
|
+
89.bg.as_words.should == 'осемдесет и девет'
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
it "should work with numbers less than 1000, divisable by 100" do
|
47
|
+
%w[сто двеста триста четиристотин петстотин шестстотин седемстотин осемстотин деветстотин].zip([100, 200, 300, 400, 500, 600, 700, 800, 900]).each do |name, number|
|
48
|
+
number.bg.as_words.should == name
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
it "should work with numbers 100-1000, not dividable by 100" do
|
53
|
+
110.bg.as_words.should == 'сто и десет'
|
54
|
+
217.bg.as_words.should == 'двеста и седемнадесет'
|
55
|
+
420.bg.as_words.should == 'четиристотин и двадесет'
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
123.bg.as_words.should == 'сто двадесет и три'
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
it "should work with numbers divisable with 1000" do
|
61
|
+
1_000.bg.as_words.should == 'хиляда'
|
62
|
+
2_000.bg.as_words.should == 'две хиляди'
|
63
|
+
5_000.bg.as_words.should == 'пет хиляди'
|
64
|
+
10_000.bg.as_words.should == 'десет хиляди'
|
65
|
+
13_000.bg.as_words.should == 'тринадесет хиляди'
|
66
|
+
28_000.bg.as_words.should == 'двадесет и осем хиляди'
|
67
|
+
100_000.bg.as_words.should == 'сто хиляди'
|
68
|
+
673_000.bg.as_words.should == 'шестстотин седемдесет и три хиляди'
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
it "should work with numbers less than 1 000 000, not divisable with 1000" do
|
72
|
+
1_001.bg.as_words.should == 'хиляда и едно'
|
73
|
+
1_024.bg.as_words.should == 'хиляда двадесет и четири'
|
74
|
+
17_001.bg.as_words.should == 'седемнадесет хиляди и едно'
|
75
|
+
24_200.bg.as_words.should == 'двадесет и четири хиляди и двеста'
|
76
|
+
65_536.bg.as_words.should == 'шестдесет и пет хиляди петстотин тридесет и шест'
|
76
77
|
|
77
|
-
|
78
|
-
|
78
|
+
123_456.bg.as_words.should == 'сто двадесет и три хиляди четиристотин петдесет и шест'
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
it "should work with millions" do
|
82
|
+
1_000_000.bg.as_words.should == 'един милион'
|
83
|
+
1_000_001.bg.as_words.should == 'един милион и едно'
|
84
|
+
2_000_200.bg.as_words.should == 'два милиона и двеста'
|
85
|
+
35_000_035.bg.as_words.should == 'тридесет и пет милиона тридесет и пет'
|
86
|
+
123_456_789.bg.as_words.should == 'сто двадесет и три милиона четиристотин петдесет и шест хиляди седемстотин осемдесет и девет'
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
89
|
+
it "should work with big numbers in male gender" do
|
90
|
+
121_121_121.bg.as_words(:male).should == 'сто двадесет и един милиона сто двадесет и една хиляди сто двадесет и един'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should work with the integer part only" do
|
94
|
+
BigDecimal("42").bg.as_words.should == 'четиридесет и две'
|
95
|
+
BigDecimal("42.10").bg.as_words.should == 'четиридесет и две'
|
96
|
+
end
|
90
97
|
end
|
91
98
|
|
92
99
|
it "should give numbers as levas" do
|