ru_propisju 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.rdoc +1 -1
- data/lib/ru_propisju.rb +94 -87
- data/ru_propisju.gemspec +3 -3
- data/test/test_ru_propisju.rb +1 -1
- metadata +18 -8
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
== SYNOPSIS:
|
14
14
|
|
15
15
|
RuPropisju.rublej(123.78) #=> "сто двадцать три рубля 78 копеек"
|
16
|
-
RuPropisju.propisju_shtuk(212.40, 2, "сволочь", "сволочи", "сволочей") #=> "двести двенадцать целых четыре десятых сволочи"
|
16
|
+
RuPropisju.propisju_shtuk(212.40, 2, ["сволочь", "сволочи", "сволочей"]) #=> "двести двенадцать целых четыре десятых сволочи"
|
17
17
|
|
18
18
|
== REQUIREMENTS:
|
19
19
|
|
data/lib/ru_propisju.rb
CHANGED
@@ -6,7 +6,7 @@ $KCODE = 'u' if RUBY_VERSION < '1.9.0'
|
|
6
6
|
# RuPropisju.rublej(123) # "сто двадцать три рубля"
|
7
7
|
module RuPropisju
|
8
8
|
|
9
|
-
VERSION = '2.
|
9
|
+
VERSION = '2.2.0'
|
10
10
|
|
11
11
|
# http://www.xe.com/symbols.php
|
12
12
|
# (лица, приближенные форексам и всяким там валютам и курсам)
|
@@ -22,7 +22,7 @@ module RuPropisju
|
|
22
22
|
SUPPORTED_CURRENCIES = CURRENCIES.keys.join ','
|
23
23
|
|
24
24
|
TRANSLATIONS = {
|
25
|
-
|
25
|
+
'ru' => {
|
26
26
|
0 => "",
|
27
27
|
'0' => "ноль",
|
28
28
|
:thousands => ["тысяча", "тысячи", "тысяч"],
|
@@ -78,7 +78,7 @@ module RuPropisju
|
|
78
78
|
:usd_integral => ["доллар", "доллара", "долларов"],
|
79
79
|
:usd_fraction => ['цент', 'цента', 'центов'],
|
80
80
|
},
|
81
|
-
|
81
|
+
'ua' => {
|
82
82
|
0 => "",
|
83
83
|
'0' => "нуль",
|
84
84
|
:thousands => ["тисяча", "тисячі", "тисяч"],
|
@@ -133,8 +133,15 @@ module RuPropisju
|
|
133
133
|
}
|
134
134
|
}
|
135
135
|
|
136
|
+
MONEY_GENDERS = {
|
137
|
+
:rub => 1,
|
138
|
+
:usd => 1,
|
139
|
+
:uah => 2,
|
140
|
+
:eur => 1,
|
141
|
+
}
|
142
|
+
|
136
143
|
|
137
|
-
|
144
|
+
# Кидается при запросе неизвестной валюты
|
138
145
|
class UnknownCurrency < ArgumentError
|
139
146
|
end
|
140
147
|
|
@@ -177,30 +184,35 @@ module RuPropisju
|
|
177
184
|
# Выводит целое или дробное число как сумму в рублях прописью
|
178
185
|
#
|
179
186
|
# rublej(345.2) #=> "триста сорок пять рублей 20 копеек"
|
187
|
+
#
|
180
188
|
def rublej(amount, locale = :ru)
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
kop = remainder.to_i
|
195
|
-
unless kop.zero?
|
196
|
-
parts << kop << choose_plural(kop, fractions)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
parts.join(' ')
|
189
|
+
integrals_key = :rub_integral
|
190
|
+
fractions_key = :rub_fraction
|
191
|
+
money_gender = MONEY_GENDERS[:rub]
|
192
|
+
|
193
|
+
money(amount, locale, integrals_key, fractions_key, money_gender, true)
|
194
|
+
end
|
195
|
+
|
196
|
+
# Выводит целое или дробное число как сумму в расширенном формате
|
197
|
+
#
|
198
|
+
# rublej_extended_format(345.2) #=> "345 рублей 20 копеек (триста сорок пять рублей 20 копеек)"
|
199
|
+
#
|
200
|
+
def rublej_extended_format(amount, locale = :ru)
|
201
|
+
"#{digit_rublej(amount, locale)} (#{rublej(amount, locale)})"
|
202
202
|
end
|
203
203
|
|
204
|
+
# Выводит целое или дробное число как сумму в рублях и копейках не прописью
|
205
|
+
#
|
206
|
+
# digit_rublej(345.2) #=> "345 рублей 20 копеек"
|
207
|
+
#
|
208
|
+
|
209
|
+
def digit_rublej(amount, locale = :ru)
|
210
|
+
integrals_key = :rub_integral
|
211
|
+
fractions_key = :rub_fraction
|
212
|
+
money_gender = MONEY_GENDERS[:rub]
|
213
|
+
|
214
|
+
money(amount, locale, integrals_key, fractions_key, money_gender, true, true)
|
215
|
+
end
|
204
216
|
# Выбирает корректный вариант числительного в зависимости от рода и числа и оформляет сумму прописью
|
205
217
|
#
|
206
218
|
# propisju(243) => "двести сорок три"
|
@@ -216,75 +228,34 @@ module RuPropisju
|
|
216
228
|
# Выводит целое или дробное число как сумму в гривнах прописью
|
217
229
|
#
|
218
230
|
# griven(32) #=> "тридцать две гривны"
|
219
|
-
def griven(amount, locale =
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
|
226
|
-
|
227
|
-
parts = []
|
228
|
-
parts << propisju_int(amount.to_i, 2, integrals, locale) unless amount.to_i == 0
|
229
|
-
if amount.kind_of? Float
|
230
|
-
remainder = (amount.divmod(1)[1]*100).round
|
231
|
-
if remainder == 100
|
232
|
-
parts = [propisju_int(amount.to_i + 1, 2, integrals, locale)]
|
233
|
-
else
|
234
|
-
parts << propisju_int(remainder.to_i, 2, fractions, locale)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
parts.join(' ')
|
231
|
+
def griven(amount, locale = :ru)
|
232
|
+
integrals_key = :uah_integral
|
233
|
+
fractions_key = :uah_fraction
|
234
|
+
money_gender = MONEY_GENDERS[:uah]
|
235
|
+
|
236
|
+
money(amount, locale, integrals_key, fractions_key, money_gender)
|
238
237
|
end
|
239
238
|
|
240
239
|
# Выводит целое или дробное число как сумму в долларах прописью
|
241
240
|
#
|
242
241
|
# dollarov(32) #=> "тридцать два доллара"
|
243
|
-
def dollarov(amount, locale =
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
integrals = locale_root[:usd_integral]
|
248
|
-
fractions = locale_root[:usd_fraction]
|
249
|
-
|
250
|
-
return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
|
251
|
-
|
252
|
-
parts << propisju_int(amount.to_i, 1, integrals, locale) unless amount.to_i == 0
|
253
|
-
if amount.kind_of?(Float)
|
254
|
-
remainder = (amount.divmod(1)[1]*100).round
|
255
|
-
if (remainder == 100)
|
256
|
-
parts = [propisju_int(amount.to_i + 1, 1, integrals, locale)]
|
257
|
-
else
|
258
|
-
parts << propisju_int(remainder.to_i, 1, fractions, locale)
|
259
|
-
end
|
260
|
-
end
|
242
|
+
def dollarov(amount, locale = :ru)
|
243
|
+
integrals_key = :usd_integral
|
244
|
+
fractions_key = :usd_fraction
|
245
|
+
money_gender = MONEY_GENDERS[:usd]
|
261
246
|
|
262
|
-
|
247
|
+
money(amount, locale, integrals_key, fractions_key, money_gender)
|
263
248
|
end
|
264
249
|
|
265
250
|
# Выводит целое или дробное число как сумму в евро прописью
|
266
251
|
#
|
267
252
|
# evro(32) #=> "тридцать два евро"
|
268
|
-
def evro(amount, locale =
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
integrals = locale_data[:eur_integral]
|
273
|
-
fractions = locale_data[:eur_fraction]
|
274
|
-
|
275
|
-
return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
|
276
|
-
|
277
|
-
parts << propisju_int(amount.to_i, 1, integrals, locale) unless amount.to_i == 0
|
278
|
-
if amount.kind_of?(Float)
|
279
|
-
remainder = (amount.divmod(1)[1]*100).round
|
280
|
-
if (remainder == 100)
|
281
|
-
parts = [propisju_int(amount.to_i + 1, 1, integrals, locale)]
|
282
|
-
else
|
283
|
-
parts << propisju_int(remainder.to_i, 1, fractions, locale)
|
284
|
-
end
|
285
|
-
end
|
253
|
+
def evro(amount, locale = :ru)
|
254
|
+
integrals_key = :eur_integral
|
255
|
+
fractions_key = :eur_fraction
|
256
|
+
money_gender = MONEY_GENDERS[:eur]
|
286
257
|
|
287
|
-
|
258
|
+
money(amount, locale, integrals_key, fractions_key, money_gender)
|
288
259
|
end
|
289
260
|
|
290
261
|
# Выводит сумму прописью в рублях по количеству копеек
|
@@ -308,11 +279,45 @@ module RuPropisju
|
|
308
279
|
elements.join(" ")
|
309
280
|
end
|
310
281
|
|
282
|
+
def money(amount, locale, integrals_key, fractions_key, money_gender, fraction_as_number = false, integrals_as_number = false)
|
283
|
+
locale_data = pick_locale(TRANSLATIONS, locale)
|
284
|
+
integrals = locale_data[integrals_key]
|
285
|
+
fractions = locale_data[fractions_key]
|
286
|
+
|
287
|
+
return zero(locale_data, integrals, fractions, fraction_as_number, integrals_as_number) if amount.zero?
|
288
|
+
|
289
|
+
parts = []
|
290
|
+
if integrals_as_number
|
291
|
+
parts << amount.to_i << choose_plural(amount, integrals) unless amount.to_i == 0
|
292
|
+
else
|
293
|
+
parts << propisju_int(amount.to_i, money_gender, integrals, locale) unless amount.to_i == 0
|
294
|
+
end
|
295
|
+
|
296
|
+
if amount.kind_of?(Float)
|
297
|
+
remainder = (amount.divmod(1)[1]*100).round
|
298
|
+
if remainder == 100
|
299
|
+
parts = [propisju_int(amount.to_i + 1, money_gender, integrals, locale)]
|
300
|
+
else
|
301
|
+
if fraction_as_number
|
302
|
+
kop = remainder.to_i
|
303
|
+
unless kop.zero?
|
304
|
+
parts << kop << choose_plural(kop, fractions)
|
305
|
+
end
|
306
|
+
else
|
307
|
+
parts << propisju_int(remainder.to_i, money_gender, fractions, locale)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
parts.join(' ')
|
313
|
+
end
|
314
|
+
|
311
315
|
private
|
312
|
-
|
313
|
-
def zero(locale_data, integrals, fractions, fraction_as_number)
|
316
|
+
|
317
|
+
def zero(locale_data, integrals, fractions, fraction_as_number, integrals_as_number)
|
318
|
+
integ = integrals_as_number ? '0' : locale_data['0']
|
314
319
|
frac = fraction_as_number ? '0' : locale_data['0']
|
315
|
-
parts = [
|
320
|
+
parts = [integ , integrals[-1], frac, fractions[-1]]
|
316
321
|
parts.join(' ')
|
317
322
|
end
|
318
323
|
|
@@ -414,7 +419,7 @@ module RuPropisju
|
|
414
419
|
# Выдает сумму прописью с учетом дробной доли. Дробная доля округляется до миллионной, или (если
|
415
420
|
# дробная доля оканчивается на нули) до ближайшей доли ( 500 тысячных округляется до 5 десятых).
|
416
421
|
# Дополнительный аргумент - род существительного (1 - мужской, 2- женский, 3-средний)
|
417
|
-
def propisju_float(num, locale =
|
422
|
+
def propisju_float(num, locale = :ru)
|
418
423
|
locale_root = pick_locale(DECIMALS, locale)
|
419
424
|
source_expression = locale_root[:prefix][0]
|
420
425
|
target_prefix = locale_root[:prefix][1]
|
@@ -453,7 +458,9 @@ module RuPropisju
|
|
453
458
|
locale_root = pick_locale(TRANSLATIONS, locale)
|
454
459
|
|
455
460
|
# zero!
|
456
|
-
|
461
|
+
if amount.zero?
|
462
|
+
return [locale_root['0'], item_forms[-1]].compact.join(' ')
|
463
|
+
end
|
457
464
|
|
458
465
|
fractions = [
|
459
466
|
[:trillions, 1_000_000_000_000],
|
data/ru_propisju.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ru_propisju"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Julik Tarkhanov"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-03-24"
|
13
13
|
s.email = "me@julik.nl"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.homepage = "http://github.com/julik/ru_propisju"
|
27
27
|
s.licenses = ["MIT"]
|
28
28
|
s.require_paths = ["lib"]
|
29
|
-
s.rubygems_version = "1.8.
|
29
|
+
s.rubygems_version = "1.8.24"
|
30
30
|
s.summary = "C\u{443}\u{43c}\u{43c}\u{430} \u{43f}\u{440}\u{43e}\u{43f}\u{438}\u{441}\u{44c}\u{44e}"
|
31
31
|
|
32
32
|
if s.respond_to? :specification_version then
|
data/test/test_ru_propisju.rb
CHANGED
@@ -155,7 +155,7 @@ class TestRuPropisju < Test::Unit::TestCase
|
|
155
155
|
assert_equal "триста тридцать две гривны", RuPropisju.griven(331.995)
|
156
156
|
assert_equal "одна гривна", RuPropisju.grivna(1)
|
157
157
|
assert_equal "три гривны четырнадцать копеек", RuPropisju.grivny(3.14)
|
158
|
-
assert_equal "ноль гривен
|
158
|
+
assert_equal "ноль гривен ноль копеек", RuPropisju.griven(0)
|
159
159
|
|
160
160
|
# ua locale
|
161
161
|
assert_equal "сто двадцять три гривні", RuPropisju.griven(123, :ua)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ru_propisju
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jeweler
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rake
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description:
|
37
47
|
email: me@julik.nl
|
38
48
|
executables: []
|
@@ -62,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
72
|
version: '0'
|
63
73
|
segments:
|
64
74
|
- 0
|
65
|
-
hash:
|
75
|
+
hash: -4443001232636317022
|
66
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
77
|
none: false
|
68
78
|
requirements:
|
@@ -71,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
81
|
version: '0'
|
72
82
|
requirements: []
|
73
83
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.24
|
75
85
|
signing_key:
|
76
86
|
specification_version: 3
|
77
87
|
summary: Cумма прописью
|