kabal 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33439037203abe61216a142cac5d9c02d06c238a
4
- data.tar.gz: 7d5f04457e6e752f39a7e5fdb4dc6b5f11a1046a
3
+ metadata.gz: d22c90bd40aac3a8ba178f098bba486a0bfc9d49
4
+ data.tar.gz: 2e3f54d404fd4585828a8587c381e8d1ea29c250
5
5
  SHA512:
6
- metadata.gz: 74532cb19862e75ac0b1526d18a00176b23a62d42f6941f176375413edce92f4f287a8c1758f9f5d8453579e73c66e4616a91863d2fbac1a669b317a087eed2e
7
- data.tar.gz: ca456203cb903d8b62bc9c00a5e78400989ec92801860421a59f54a850e879b25b8edb61bcca204eb304a7f2071e2c1db913f793ec705aaa3651c8f870cae08a
6
+ metadata.gz: 9ac8dce387eae4fee82ee671cb233cea6bee2b3043423fe12f1b66a6279bf27ddfe23e6d2089fc0a29ef6b2a26efb8c89745cef73476e931757eee5a24bd5428
7
+ data.tar.gz: 681ffb3be175372b594c56182b6cd3bcdcf2ab11babf0075c69fe1311f1e7c32f05cd4fbc8aa2688e328d82fc6700fdae19dbef0e7eeed73902d62be641b617c
data/README.md CHANGED
@@ -24,6 +24,7 @@ Or install it yourself as:
24
24
  Kabal has one main feature - number to text "converting".
25
25
 
26
26
  require 'kabal'
27
+ include Kabal
27
28
  Kabal.to_text 1 #=> "один"
28
29
 
29
30
  You can choose language to "converting".
@@ -13,11 +13,11 @@ class Kabal::Russian < Kabal::Language
13
13
  end
14
14
 
15
15
  def single(number)
16
- if (number == 1 or number == 2) and @count and @count / 10 != 1 and @number_order == 3
17
- names[lang]["single_feminine"][@count % 10]
18
- else
19
- names[lang]["single"][number]
16
+ if @feminine_name_for_thousands
17
+ @feminine_name_for_thousands = false
18
+ return names[lang]["single_feminine"][count(number) % 10]
20
19
  end
20
+ names[lang]["single"][number]
21
21
  end
22
22
 
23
23
  def two_words(number)
@@ -28,9 +28,7 @@ class Kabal::Russian < Kabal::Language
28
28
  end
29
29
 
30
30
  def three_words(number)
31
- if number / 100 == 0
32
- return two_words number
33
- end
31
+ return two_words number if number / 100 == 0
34
32
  number_name = names[lang]["three_words"][number / 100]
35
33
  return number_name += " " + two_words(number % 100) if (number % 100 >= 20)
36
34
  return number_name += " " + single(number % 100) if (number % 100 != 0)
@@ -39,30 +37,46 @@ class Kabal::Russian < Kabal::Language
39
37
 
40
38
  def ten_powers(number)
41
39
  #FIXME find better way
42
- @number_order = ((number.to_s.length - 1) / 3) * 3
43
- if @number_order < 3
44
- unless number == 0
45
- @number_name += " " + three_words(number % 1000)
46
- end
47
- return @number_name
48
- end
49
- @count = number / (10 ** @number_order)
50
- if number_is_google?
51
- return names[lang]["ten_powers"][100]
52
- end
40
+ return names[lang]["ten_powers"][100] if number_is_google? number
41
+ less_thousands number if number_is_thousands? number
42
+ return @number_name if number_is_thousands? number
43
+ create_number_name number
44
+ ten_powers(number % (10 ** number_order(number)))
45
+ end
46
+
47
+ def number_order(number)
48
+ ((number.to_s.length - 1) / 3) * 3
49
+ end
50
+
51
+ def count(number)
52
+ number / (10 ** number_order(number))
53
+ end
54
+
55
+ def create_number_name(number)
53
56
  if @number_name.nil?
54
- @number_name = count_name + " " + Declinations.name_with_declination(names[lang]["ten_powers"][@number_order], @count)
55
- elsif @count != 0
56
- @number_name += " " + count_name + " " + Declinations.name_with_declination(names[lang]["ten_powers"][@number_order], @count)
57
+ @number_name = count_name(number) + " " + Declinations.name_with_declination(names[lang]["ten_powers"][number_order(number)], count(number))
58
+ elsif count(number) != 0
59
+ @number_name += " " + count_name(number) + " " + Declinations.name_with_declination(names[lang]["ten_powers"][number_order(number)], count(number))
57
60
  end
58
- ten_powers(number % (10 ** @number_order))
59
61
  end
60
62
 
61
- def count_name
62
- three_words @count
63
+ def less_thousands(number)
64
+ unless number == 0
65
+ @number_name += " " + three_words(number % 1000)
66
+ end
67
+ end
68
+
69
+ def number_is_thousands?(number)
70
+ number_order(number) < 3
71
+ end
72
+
73
+ def count_name(number)
74
+ #FIXME number.to_S[-4] not good
75
+ @feminine_name_for_thousands = (number.to_s[-4] == "1" or number.to_s[-4] == "2") and count(number) and count(number) / 10 != 1 and number_order(number) == 3
76
+ three_words count(number)
63
77
  end
64
78
 
65
- def number_is_google?
66
- @count == 10 and @number_order == 99
79
+ def number_is_google?(number)
80
+ count(number) == 10 and number_order(number) == 99
67
81
  end
68
82
  end
data/lib/kabal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kabal
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kabal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov