kabal 0.2.10 → 0.2.11

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: 5daad58f7a22bc997876db7403be9f32e3dd3b25
4
- data.tar.gz: 2698a6ae3e7f568e4f9821cf85a67b4e18c03e4e
3
+ metadata.gz: 5b580af08037ba20f127cb0682ef45b7037e0d0d
4
+ data.tar.gz: fb214f852a961fe6ab669836b0c781e6ef1af5fc
5
5
  SHA512:
6
- metadata.gz: 2882910533b1f26caad0079c21ce14353b66a16e58a4ace8518d806ac80cfe3ee4917dd2bb793e2072f0c39bc4e8aed2e12f7d8ce18e614a455ccd355867b94c
7
- data.tar.gz: 7e52b94f4d8e72df47406f023efb8ba6349cc0b2e17264324d17e5dff8d9e101a5629e1df767aa55ac85f904239b1fa299ef2c2652b029b9ad6ea7e0071f5934
6
+ metadata.gz: 92c1d897cd2294239335a20d2c53882fadbad6c6c478d3d9c9523b31a97b304fe31b633f71aa96cfbda74adcba4ec106613eba46130cbebfac469ebba4863701
7
+ data.tar.gz: bcae9e1f9575d7a8acf3df8bf98d0268aaed22f0f31874fb5ea0248c87cd4157b2c54b787af6de92edae38851fe03c0cf43f665ca90c3ffdf020b4cac4df8940
data/lib/kabal.rb CHANGED
@@ -29,7 +29,7 @@ module Kabal
29
29
  obj = Object.const_get("Kabal::" + language_at_once).new
30
30
  obj.convert number
31
31
  else
32
- raise NoLanguageSupportError.message
32
+ NoLanguageSupportError.message
33
33
  end
34
34
  end
35
35
 
@@ -39,7 +39,7 @@ module Kabal
39
39
  obj = Object.const_get("Kabal::" + languages[language_at_once_index].first).new
40
40
  obj.convert number
41
41
  else
42
- raise NoLanguageSupportError.message
42
+ NoLanguageSupportError.message
43
43
  end
44
44
  end
45
45
 
@@ -6,8 +6,20 @@ module Kabal
6
6
  end
7
7
 
8
8
  def convert(number)
9
- check_supports_for number
10
- convert_number number
9
+ if no_supports? number
10
+ error number
11
+ else
12
+ convert_number number
13
+ end
14
+ end
15
+
16
+ def error(number)
17
+ if number_is_out_of_the_range? number
18
+ return Kabal::Errors::NumberOutRangeError.message
19
+ end
20
+ if not supports_fractional? and number % 1 != 0
21
+ Kabal::Errors::NoSupportForFractionalNumberOnCurrentLanguages.message
22
+ end
11
23
  end
12
24
 
13
25
  def lang
@@ -29,10 +41,6 @@ module Kabal
29
41
  eval @supports["natural"]["max"]
30
42
  end
31
43
 
32
- def supports_fractional?
33
- @supports["fractional"]
34
- end
35
-
36
44
  def names
37
45
  @names[lang]
38
46
  end
@@ -70,13 +78,16 @@ module Kabal
70
78
  number / (10 ** number_order(number))
71
79
  end
72
80
 
73
- def check_supports_for(number)
74
- if number % 1 != 0 and not supports_fractional?
75
- raise Kabal::Errors::NoSupportForFractionalNumberOnCurrentLanguages.message
76
- end
77
- if number >= max_value or number <= min_value
78
- raise Kabal::Errors::NumberOutRangeError.message
79
- end
81
+ def supports_fractional?
82
+ @supports["fractional"]
83
+ end
84
+
85
+ def number_is_out_of_the_range?(number)
86
+ number >= max_value or number <= min_value
87
+ end
88
+
89
+ def no_supports?(number)
90
+ (number % 1 != 0 and not supports_fractional?) or number_is_out_of_the_range?(number)
80
91
  end
81
92
  end
82
93
  end
data/lib/kabal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kabal
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.11"
3
3
  end
@@ -38,10 +38,7 @@ class EnglishTest < TestCase
38
38
  end
39
39
 
40
40
  def test_fractional_number
41
- exception = assert_raises RuntimeError do
42
- @eng.convert 0.1
43
- end
44
- assert_equal NoSupportForFractionalNumberOnCurrentLanguages.message, exception.message
41
+ assert_equal NoSupportForFractionalNumberOnCurrentLanguages.message, @eng.convert(0.1)
45
42
  end
46
43
  def test_hundred_random_numbers
47
44
  r = Random.new
@@ -46,10 +46,7 @@ class RussianTest < TestCase
46
46
  assert_equal @rus.convert(-22000), "минус двадцать две тысячи"
47
47
  end
48
48
  def test_to_text_with_negative_number
49
- exception = assert_raises RuntimeError do
50
- @rus.convert -(10 ** 103)
51
- end
52
- assert_equal NumberOutRangeError.message, exception.message
49
+ assert_equal NumberOutRangeError.message, @rus.convert(-(10 ** 103))
53
50
  end
54
51
  def test_to_text_with_fractional_number_with_zero
55
52
  assert_equal @rus.convert(0.01), "ноль целых одна сотая"
@@ -21,15 +21,10 @@ class KabalTest < TestCase
21
21
  end
22
22
 
23
23
  def test_to_text_in_language_with_unsupported_language
24
- #FIXME replace RuntimeError to NoLanguageSupportError
25
- exception = assert_raises RuntimeError do
26
- Kabal.to_text_in_language(125125125125, "Elfin")
27
- end
28
- assert_equal NoLanguageSupportError.message, exception.message
24
+ assert_equal NoLanguageSupportError.message, Kabal.to_text_in_language(125125125125, "Elfin")
29
25
  end
30
26
 
31
27
  def test_language_init_with_unsupported_language
32
- #FIXME replace RuntimeError to NoLanguageSupportError
33
28
  exception = assert_raises RuntimeError do
34
29
  Kabal.language = "Elfin"
35
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kabal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-04 00:00:00.000000000 Z
11
+ date: 2014-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler