ru_propisju 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.1.4
2
+
3
+ * Правильная обработка нулей в суммах
4
+
1
5
  === 2.1.3
2
6
 
3
7
  * Починен порядок тысячных долей на ruby 1.8x
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.1.3'
9
+ VERSION = '2.1.4'
10
10
 
11
11
  # http://www.xe.com/symbols.php
12
12
  # (лица, приближенные форексам и всяким там валютам и курсам)
@@ -178,12 +178,13 @@ module RuPropisju
178
178
  #
179
179
  # rublej(345.2) #=> "триста сорок пять рублей 20 копеек"
180
180
  def rublej(amount, locale = :ru)
181
- parts = []
182
181
  locale_data = pick_locale(TRANSLATIONS, locale)
183
-
184
182
  integrals = locale_data[:rub_integral]
185
183
  fractions = locale_data[:rub_fraction]
186
184
 
185
+ return zero(locale_data, integrals, fractions, locale == :ru) if amount.zero?
186
+
187
+ parts = []
187
188
  parts << propisju_int(amount.to_i, 1, integrals, locale) unless amount.to_i == 0
188
189
  if amount.kind_of?(Float)
189
190
  remainder = (amount.divmod(1)[1]*100).round
@@ -220,7 +221,9 @@ module RuPropisju
220
221
 
221
222
  integrals = locale_root[:uah_integral]
222
223
  fractions = locale_root[:uah_fraction]
223
-
224
+
225
+ return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
226
+
224
227
  parts = []
225
228
  parts << propisju_int(amount.to_i, 2, integrals, locale) unless amount.to_i == 0
226
229
  if amount.kind_of? Float
@@ -243,7 +246,9 @@ module RuPropisju
243
246
 
244
247
  integrals = locale_root[:usd_integral]
245
248
  fractions = locale_root[:usd_fraction]
246
-
249
+
250
+ return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
251
+
247
252
  parts << propisju_int(amount.to_i, 1, integrals, locale) unless amount.to_i == 0
248
253
  if amount.kind_of?(Float)
249
254
  remainder = (amount.divmod(1)[1]*100).round
@@ -266,7 +271,9 @@ module RuPropisju
266
271
 
267
272
  integrals = locale_data[:eur_integral]
268
273
  fractions = locale_data[:eur_fraction]
269
-
274
+
275
+ return zero(locale_root, integrals, fractions, locale == 'ru') if amount.zero?
276
+
270
277
  parts << propisju_int(amount.to_i, 1, integrals, locale) unless amount.to_i == 0
271
278
  if amount.kind_of?(Float)
272
279
  remainder = (amount.divmod(1)[1]*100).round
@@ -303,6 +310,11 @@ module RuPropisju
303
310
 
304
311
  private
305
312
 
313
+ def zero(locale_data, integrals, fractions, fraction_as_number)
314
+ frac = fraction_as_number ? '0' : locale_data['0']
315
+ parts = [locale_data['0'], integrals[-1], frac, fractions[-1]]
316
+ parts.join(' ')
317
+ end
306
318
 
307
319
  # Cоставляет число прописью для чисел до тысячи
308
320
 
@@ -312,6 +324,9 @@ module RuPropisju
312
324
 
313
325
  locale = locale.to_s
314
326
 
327
+ # Ноль чего-то
328
+ # return "ноль %s" % item_forms[3] if remaining_amount_or_nil.zero?
329
+
315
330
  rest, rest1, chosen_ordinal, ones, tens, hundreds = [nil]*6
316
331
 
317
332
  rest = remaining_amount % 1000
@@ -437,6 +452,9 @@ module RuPropisju
437
452
 
438
453
  locale_root = pick_locale(TRANSLATIONS, locale)
439
454
 
455
+ # zero!
456
+ return [locale_root['0'], item_forms[-1]].compact.join(' ') if amount.zero?
457
+
440
458
  fractions = [
441
459
  [:trillions, 1_000_000_000_000],
442
460
  [:billions, 1_000_000_000],
@@ -484,5 +502,5 @@ module RuPropisju
484
502
 
485
503
  public_instance_methods(true).map{|m| module_function(m) }
486
504
 
487
- module_function :propisju_int, :propisju_float, :compose_ordinal, :pick_locale
505
+ module_function :zero, :propisju_int, :propisju_float, :compose_ordinal, :pick_locale
488
506
  end
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.1.3"
8
+ s.version = "2.1.4"
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 = "2012-03-30"
12
+ s.date = "2012-04-02"
13
13
  s.email = "me@julik.nl"
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -26,8 +26,8 @@ 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.16"
30
- s.summary = "C\321\203\320\274\320\274\320\260 \320\277\321\200\320\276\320\277\320\270\321\201\321\214\321\216"
29
+ s.rubygems_version = "1.8.15"
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
33
33
  s.specification_version = 3
@@ -63,6 +63,7 @@ class TestRuPropisju < Test::Unit::TestCase
63
63
  assert_equal "сорок пять", RuPropisju.propisju(45, 1)
64
64
  assert_equal "пять", RuPropisju.propisju(5, 1)
65
65
  assert_equal "шестьсот двенадцать", RuPropisju.propisju(612, 1)
66
+ assert_equal "ноль", RuPropisju.propisju(0, 1)
66
67
 
67
68
 
68
69
  # ukrainian locale
@@ -129,6 +130,7 @@ class TestRuPropisju < Test::Unit::TestCase
129
130
  end
130
131
 
131
132
  def test_rublej
133
+ assert_equal "ноль рублей 0 копеек", RuPropisju.rublej(0)
132
134
  assert_equal "сто двадцать три рубля", RuPropisju.rublej(123)
133
135
  assert_equal "триста сорок три рубля 20 копеек", RuPropisju.rublej(343.20)
134
136
  assert_equal "42 копейки", RuPropisju.rublej(0.4187)
@@ -153,6 +155,8 @@ class TestRuPropisju < Test::Unit::TestCase
153
155
  assert_equal "триста тридцать две гривны", RuPropisju.griven(331.995)
154
156
  assert_equal "одна гривна", RuPropisju.grivna(1)
155
157
  assert_equal "три гривны четырнадцать копеек", RuPropisju.grivny(3.14)
158
+ assert_equal "ноль гривен 0 копеек", RuPropisju.griven(0)
159
+
156
160
  # ua locale
157
161
  assert_equal "сто двадцять три гривні", RuPropisju.griven(123, :ua)
158
162
  assert_equal "сто двадцять чотири гривні", RuPropisju.griven(124, :ua)
@@ -161,10 +165,12 @@ class TestRuPropisju < Test::Unit::TestCase
161
165
  assert_equal "триста тридцять дві гривні", RuPropisju.griven(331.995, :ua)
162
166
  assert_equal "одна гривня", RuPropisju.grivna(1, :ua)
163
167
  assert_equal "три гривні чотирнадцять копійок", RuPropisju.grivny(3.14, :ua)
168
+ assert_equal "нуль гривень нуль копійок", RuPropisju.griven(0, :ua)
164
169
 
165
170
  end
166
171
 
167
172
  def test_kopeek
173
+ assert_equal "ноль рублей 0 копеек", RuPropisju.kopeek(0)
168
174
  assert_equal "сто двадцать три рубля", RuPropisju.kopeek(12300)
169
175
  assert_equal "три рубля 14 копеек", RuPropisju.kopeek(314)
170
176
  assert_equal "32 копейки", RuPropisju.kopeek(32)
metadata CHANGED
@@ -1,59 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ru_propisju
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.4
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 1
9
- - 3
10
- version: 2.1.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Julik Tarkhanov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :development
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- prerelease: false
32
- requirement: *id001
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: jeweler
34
- - !ruby/object:Gem::Dependency
35
- type: :development
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &8967760 !ruby/object:Gem::Requirement
37
17
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
45
23
  prerelease: false
46
- requirement: *id002
24
+ version_requirements: *8967760
25
+ - !ruby/object:Gem::Dependency
47
26
  name: rake
27
+ requirement: &8967000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *8967000
48
36
  description:
49
37
  email: me@julik.nl
50
38
  executables: []
51
-
52
39
  extensions: []
53
-
54
- extra_rdoc_files:
40
+ extra_rdoc_files:
55
41
  - README.rdoc
56
- files:
42
+ files:
57
43
  - Gemfile
58
44
  - History.txt
59
45
  - README.rdoc
@@ -62,39 +48,31 @@ files:
62
48
  - ru_propisju.gemspec
63
49
  - test/test_ru_propisju.rb
64
50
  homepage: http://github.com/julik/ru_propisju
65
- licenses:
51
+ licenses:
66
52
  - MIT
67
53
  post_install_message:
68
54
  rdoc_options: []
69
-
70
- require_paths:
55
+ require_paths:
71
56
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
57
+ required_ruby_version: !ruby/object:Gem::Requirement
73
58
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
79
64
  - 0
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ hash: 792091439
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
67
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
90
72
  requirements: []
91
-
92
73
  rubyforge_project:
93
- rubygems_version: 1.8.16
74
+ rubygems_version: 1.8.15
94
75
  signing_key:
95
76
  specification_version: 3
96
- summary: !binary |
97
- Q9GD0LzQvNCwINC/0YDQvtC/0LjRgdGM0Y4=
98
-
77
+ summary: Cумма прописью
99
78
  test_files: []
100
-