number_to_words_ru 0.2.2 → 0.2.3

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.
@@ -15,6 +15,12 @@ module ArrayAdditions
15
15
  figures_array_in_capacity(capacity).reverse.join.to_i
16
16
  end
17
17
 
18
+ def number_for_gender capacity
19
+ figures = figures_array_in_capacity(capacity)
20
+ teens = figures.teens
21
+ teens ? teens.join.to_i : figures.first
22
+ end
23
+
18
24
  def is_a_thousand_capacity? capacity
19
25
  THOUSAND_CAPACITY == capacity
20
26
  end
@@ -33,7 +33,7 @@ module Strategies
33
33
  strings
34
34
  end
35
35
 
36
- if !number_in_capacity_by_words.empty?
36
+ unless number_in_capacity_by_words.empty?
37
37
  words.push translation_megs(capacity) if 0 < capacity
38
38
  words += number_in_capacity_by_words
39
39
  end
@@ -31,9 +31,9 @@ module Strategies
31
31
  strings figures.is_a_thousand_capacity?(capacity) ? :female : :male
32
32
  end
33
33
 
34
- if !number_in_capacity_by_words.empty?
34
+ unless number_in_capacity_by_words.empty?
35
35
  if 0 < capacity
36
- words.push translation_megs(capacity, figures.number_in_capacity(capacity))
36
+ words.push translation_megs(capacity, figures.number_for_gender(capacity))
37
37
  end
38
38
  words += number_in_capacity_by_words
39
39
  end
@@ -132,147 +132,161 @@ describe Integer do
132
132
  join(' ') }
133
133
  end
134
134
 
135
- describe 'few' do
136
- context '2000 as lower example' do
137
- subject { 2000 }
135
+ context '21000 as uniq example' do
136
+ subject { 21000 }
138
137
 
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
138
+ its(:to_words) { should == [
139
+ t(:tens)[2], t(:ones_female)[1], t(:thousands, :count => 1)
140
+ ].join(' ') }
183
141
  end
184
142
  end
185
- end
186
143
 
187
- describe 'millions' do
188
- describe 'one' do
189
- context '1000000 as uniq example' do
190
- subject { 1000000 }
144
+ describe 'few' do
145
+ context '2000 as lower example' do
146
+ subject { 2000 }
191
147
 
192
- its(:to_words) { should == [t(:ones_male)[1], t(:millions, :count => 1)].
148
+ its(:to_words) { should == [t(:ones_female)[2], t(:thousands, :count => 2)].
193
149
  join(' ') }
194
150
  end
195
- end
196
151
 
197
- context 'few' do
198
- context '2000000 as lower example in few' do
199
- subject { 2000000 }
152
+ context '4000 as upper example' do
153
+ subject { 4000 }
200
154
 
201
- its(:to_words) { should == [t(:ones_male)[2], t(:millions, :count => 2)].
155
+ its(:to_words) { should == [t(:ones_female)[4], t(:thousands, :count => 4)].
202
156
  join(' ') }
203
157
  end
158
+ end
204
159
 
205
- context '4000000 as upper example in few' do
206
- subject { 4000000 }
160
+ describe 'many' do
161
+ context '5000 as lower example' do
162
+ subject { 5000 }
207
163
 
208
- its(:to_words) { should == [t(:ones_male)[4], t(:millions, :count => 4)].
164
+ its(:to_words) { should == [t(:ones_female)[5], t(:thousands, :count => 5)].
209
165
  join(' ') }
210
166
  end
211
- end
212
167
 
213
- context 'many' do
214
- context '5000000 as lower example in many' do
215
- subject { 5000000 }
168
+ context '11000 as uniq example' do
169
+ subject { 11000 }
216
170
 
217
- its(:to_words) { should == [t(:ones_male)[5], t(:millions, :count => 5)].
218
- join(' ') }
171
+ its(:to_words) { should == [t(:teens)[1], t(:thousands, :count => 11)].join(' ') }
219
172
  end
220
173
 
221
- context '99900000 as upper example' do
222
- subject { 999000000 }
174
+ context '999000 as upper example' do
175
+ subject { 999000 }
223
176
 
224
177
  its(:to_words) { should == [t(:hundreds)[9],
225
178
  t(:tens)[9],
226
- t(:ones_male)[9],
227
- t(:millions, :count => 999)
179
+ t(:ones_female)[9],
180
+ t(:thousands, :count => 999)
228
181
  ].join(' ') }
229
182
  end
230
183
  end
231
184
 
232
- context 'custom' do
233
- context '999000999 as example with first capacity' do
234
- subject { 999000999 }
185
+ describe 'custom' do
186
+ context '999999 as example with first capacity' do
187
+ subject { 999999 }
235
188
 
236
189
  its(:to_words) { should == [t(:hundreds)[9],
237
190
  t(:tens)[9],
238
- t(:ones_male)[9],
239
- t(:millions, :count => 999),
191
+ t(:ones_female)[9],
192
+ t(:thousands, :count => 999),
240
193
  t(:hundreds)[9],
241
194
  t(:tens)[9],
242
195
  t(:ones_male)[9],
243
196
  ].join(' ') }
244
197
  end
198
+ end
199
+ end
200
+ end
245
201
 
246
- context '999999000 as example with second capacity' do
247
- subject { 999999000 }
202
+ describe 'millions' do
203
+ describe 'one' do
204
+ context '1000000 as uniq example' do
205
+ subject { 1000000 }
248
206
 
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
207
+ its(:to_words) { should == [t(:ones_male)[1], t(:millions, :count => 1)].
208
+ join(' ') }
209
+ end
210
+ end
259
211
 
260
- context '999999999 as example with first and second capacity' do
261
- subject { 999999999 }
212
+ context 'few' do
213
+ context '2000000 as lower example in few' do
214
+ subject { 2000000 }
262
215
 
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
216
+ its(:to_words) { should == [t(:ones_male)[2], t(:millions, :count => 2)].
217
+ join(' ') }
218
+ end
219
+
220
+ context '4000000 as upper example in few' do
221
+ subject { 4000000 }
222
+
223
+ its(:to_words) { should == [t(:ones_male)[4], t(:millions, :count => 4)].
224
+ join(' ') }
225
+ end
226
+ end
227
+
228
+ context 'many' do
229
+ context '5000000 as lower example in many' do
230
+ subject { 5000000 }
231
+
232
+ its(:to_words) { should == [t(:ones_male)[5], t(:millions, :count => 5)].
233
+ join(' ') }
234
+ end
235
+
236
+ context '99900000 as upper example' do
237
+ subject { 999000000 }
238
+
239
+ its(:to_words) { should == [t(:hundreds)[9],
240
+ t(:tens)[9],
241
+ t(:ones_male)[9],
242
+ t(:millions, :count => 999)
243
+ ].join(' ') }
244
+ end
245
+ end
246
+
247
+ context 'custom' do
248
+ context '999000999 as example with first capacity' do
249
+ subject { 999000999 }
250
+
251
+ its(:to_words) { should == [t(:hundreds)[9],
252
+ t(:tens)[9],
253
+ t(:ones_male)[9],
254
+ t(:millions, :count => 999),
255
+ t(:hundreds)[9],
256
+ t(:tens)[9],
257
+ t(:ones_male)[9],
258
+ ].join(' ') }
259
+ end
260
+
261
+ context '999999000 as example with second capacity' do
262
+ subject { 999999000 }
263
+
264
+ its(:to_words) { should == [t(:hundreds)[9],
265
+ t(:tens)[9],
266
+ t(:ones_male)[9],
267
+ t(:millions, :count => 999),
268
+ t(:hundreds)[9],
269
+ t(:tens)[9],
270
+ t(:ones_female)[9],
271
+ t(:thousands, :count => 999),
272
+ ].join(' ') }
273
+ end
274
+
275
+ context '999999999 as example with first and second capacity' do
276
+ subject { 999999999 }
277
+
278
+ its(:to_words) { should == [t(:hundreds)[9],
279
+ t(:tens)[9],
280
+ t(:ones_male)[9],
281
+ t(:millions, :count => 999),
282
+ t(:hundreds)[9],
283
+ t(:tens)[9],
284
+ t(:ones_female)[9],
285
+ t(:thousands, :count => 999),
286
+ t(:hundreds)[9],
287
+ t(:tens)[9],
288
+ t(:ones_male)[9],
289
+ ].join(' ') }
276
290
  end
277
291
  end
278
292
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: number_to_words_ru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire: number_to_words_ru
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000Z
12
+ date: 2011-12-15 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Simple convert number to russian words using I18N.
15
15
  email: k.s.lazarev@gmail.com
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  segments:
57
57
  - 0
58
- hash: -459699541414322395
58
+ hash: 1036402517106089977
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  none: false
61
61
  requirements: