kabal 0.2.16 → 0.2.17

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: 9dd14ac5592f0825dcef46c3c338d7221a70f7e3
4
- data.tar.gz: efbb5aad0a5e0806c8d76c9ac6b239f8d04bc703
3
+ metadata.gz: d39a7af74516c2775b90dbe30f456e4bee5ea60b
4
+ data.tar.gz: 663a90b0bfce2fec9703881377db0cac032e016c
5
5
  SHA512:
6
- metadata.gz: 283bcb117219ed5e447c73e060d286e14ce7fdaa0f1c6b5bc714e0171593194860487fb60fb08d4e74c7436e55e56200c1570551995d86652a7edb5d83d03e3d
7
- data.tar.gz: 2ac0141bf1c870138999d900bb3aed42862251b83b2a11dc7fafdd6dc337f6a48403af6faae2404466c1e0d12c3b025855e16a41f637e26d51e5552a8de064ee
6
+ metadata.gz: cd9f650d42390c04015f669c2d1d3b7aaf4bc7e337e4e5145c11f48cd2014e7012c988ba51130494afc14c2da5e85239aa9b7f7b329d92f77af4e9413431ec96
7
+ data.tar.gz: 109a7bf5fe2bc27c3a5650033a84cf5d99eb91f00d001f595bb57fbe3853a79d3b630497074f404c0dc0372c66ac5a5b5739f1bfabf66442f67852bfd0021e25
@@ -0,0 +1,32 @@
1
+ module Kabal
2
+ module EnglishRules
3
+ module FractionalNumbers
4
+ def fractional_number_name(number)
5
+ if whole_part_name(number) != ""
6
+ whole_part_name(number) + " " + dot + " " + fractional_part_name(number)
7
+ else
8
+ dot + " " + fractional_part_name(number)
9
+ end
10
+ end
11
+
12
+ def whole_part_name(number)
13
+ count = number.to_s.split('.')[0].to_i
14
+ count != 0 ? natural_number_name(count) : ""
15
+ end
16
+
17
+ def fractional_part_name(number)
18
+ name = ""
19
+ count_string = number.to_s.split('.')[1]
20
+ count = count_string.to_i
21
+ if count_string.size != count.to_s.size
22
+ (count.to_s.size..count_string.size - 1).each do
23
+ name += names["single"][0] + " "
24
+ end
25
+ name + natural_number_name(count)
26
+ else
27
+ natural_number_name(count)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ module Kabal
2
+ module EnglishRules
3
+ module NaturalNumbers
4
+ def natural_number_name(number)
5
+ return single number if number >= 0 and number <= 19
6
+ return two_words number if number >= 0 and number <= 99
7
+ return three_words number if number >= 100 and number <= 999
8
+ ten_powers number if number >= 100
9
+ end
10
+ def single(number)
11
+ names["single"][number]
12
+ end
13
+
14
+ def two_words(number)
15
+ return single number if number <= 19
16
+ number_name = names["two_words"][number / 10]
17
+ number_name += " " + single(number % 10) if (number % 10 != 0)
18
+ number_name
19
+ end
20
+
21
+ def three_words(number)
22
+ return two_words number if number <= 99
23
+ number_name = single(number / 100) + " " + names["ten_powers"][2]
24
+ number_name += " " + two_words(number % 100) if (number % 100 >= 10)
25
+ number_name += " and " + single(number % 100) if (number % 100 < 10)
26
+ number_name
27
+ end
28
+
29
+ def ten_powers(number)
30
+ less_thousands number if number_is_thousands? number
31
+ return @number_name if number_is_thousands? number
32
+ create_number_name number
33
+ ten_powers number % (10 ** number_order(number))
34
+ end
35
+
36
+ def create_number_name(number)
37
+ if @number_name.nil?
38
+ @number_name = count_name(number) + " " + names["ten_powers"][number_order(number)]
39
+ elsif count(number) != 0
40
+ @number_name += " " + count_name(number) + " " + names["ten_powers"][number_order(number)]
41
+ end
42
+ end
43
+
44
+ def count_name(number)
45
+ three_words count(number)
46
+ end
47
+
48
+ def less_thousands(number)
49
+ @number_name += " and" if number < 100
50
+ @number_name += " " + three_words(number % 1000) unless number == 0
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,10 @@
1
1
  require 'kabal/languages/language'
2
+ require 'kabal/languages/english/natural_numbers'
3
+ require 'kabal/languages/english/fractional_numbers'
2
4
 
3
5
  class Kabal::English < Kabal::Language
6
+ include Kabal::EnglishRules::NaturalNumbers
7
+ include Kabal::EnglishRules::FractionalNumbers
4
8
  def convert_number(number)
5
9
  if need_minus? number
6
10
  minus + " " + number_words(-number)
@@ -8,60 +12,9 @@ class Kabal::English < Kabal::Language
8
12
  number_words number
9
13
  end
10
14
  end
11
- def number_words(number)
12
- return single number if number >= 0 and number <= 19
13
- return two_words number if number >= 0 and number <= 99
14
- return three_words number if number >= 100 and number <= 999
15
- ten_powers number if number >= 100
16
- end
17
- def natural_number_name(number)
18
- #FIXME switch case next lines
19
- return single(number) if number >= 0 and number <= 19
20
- return two_words(number) if number >= 20 and number <= 99
21
- return three_words(number) if number >= 100 and number <= 999
22
- ten_powers(number) if number >= 1000
23
- end
24
-
25
- def single(number)
26
- names["single"][number]
27
- end
28
-
29
- def two_words(number)
30
- return single number if number <= 19
31
- number_name = names["two_words"][number / 10]
32
- number_name += " " + single(number % 10) if (number % 10 != 0)
33
- number_name
34
- end
35
-
36
- def three_words(number)
37
- return two_words number if number <= 99
38
- number_name = single(number / 100) + " " + names["ten_powers"][2]
39
- number_name += " " + two_words(number % 100) if (number % 100 >= 10)
40
- number_name += " and " + single(number % 100) if (number % 100 < 10)
41
- number_name
42
- end
43
15
 
44
- def ten_powers(number)
45
- less_thousands number if number_is_thousands? number
46
- return @number_name if number_is_thousands? number
47
- create_number_name number
48
- ten_powers number % (10 ** number_order(number))
49
- end
50
-
51
- def create_number_name(number)
52
- if @number_name.nil?
53
- @number_name = count_name(number) + " " + names["ten_powers"][number_order(number)]
54
- elsif count(number) != 0
55
- @number_name += " " + count_name(number) + " " + names["ten_powers"][number_order(number)]
56
- end
57
- end
58
-
59
- def count_name(number)
60
- three_words count(number)
61
- end
62
-
63
- def less_thousands(number)
64
- @number_name += " and" if number < 100
65
- @number_name += " " + three_words(number % 1000) unless number == 0
16
+ def number_words(number)
17
+ return natural_number_name number.round if natural? number
18
+ fractional_number_name number if fractional? number
66
19
  end
67
20
  end
@@ -53,11 +53,14 @@ module Kabal
53
53
  names["whole"]
54
54
  end
55
55
 
56
+ def dot
57
+ names["dot"]
58
+ end
59
+
56
60
  def fractional?(number)
57
61
  number % 1 != 0
58
62
  end
59
63
 
60
-
61
64
  def natural?(number)
62
65
  number % 1 == 0
63
66
  end
data/lib/kabal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kabal
2
- VERSION = "0.2.16"
2
+ VERSION = "0.2.17"
3
3
  end
@@ -36,10 +36,6 @@ class EnglishTest < TestCase
36
36
  def test_hundred_millions_with_and
37
37
  assert_equal @eng.convert(111150021), "one hundred eleven million one hundred fifty thousand and twenty one"
38
38
  end
39
-
40
- def test_fractional_number
41
- assert_equal NoSupportForFractionalNumberOnCurrentLanguages.message, @eng.convert(0.1)
42
- end
43
39
  def test_hundred_random_numbers
44
40
  r = Random.new
45
41
  (1..63).each do |power|
@@ -56,4 +52,24 @@ class EnglishTest < TestCase
56
52
  def test_minus_one_hundred_fifty
57
53
  assert_equal "minus one hundred fifty", @eng.convert(-150)
58
54
  end
55
+ def test_1_point_5
56
+ assert_equal "one point five", @eng.convert(1.5)
57
+ assert_equal "minus one point five", @eng.convert(-1.5)
58
+ end
59
+ def test_125_point_125
60
+ assert_equal "one hundred twenty five point one hundred twenty five", @eng.convert(125.125)
61
+ assert_equal "minus one hundred twenty five point one hundred twenty five", @eng.convert(-125.125)
62
+ end
63
+ def test_zero_point_one
64
+ assert_equal "point one", @eng.convert(0.1)
65
+ assert_equal "minus point one", @eng.convert(-0.1)
66
+ end
67
+ def test_one_point_zero_five
68
+ assert_equal "one point zero five", @eng.convert(1.05)
69
+ assert_equal "minus one point zero five", @eng.convert(-1.05)
70
+ end
71
+ def test_one_point_zero_zero_zero_zero_zero_zero_zero_five
72
+ assert_equal "one point zero zero zero zero zero zero zero five", @eng.convert(1.00000005)
73
+ assert_equal "minus one point zero zero zero zero zero zero zero five", @eng.convert(-1.00000005)
74
+ end
59
75
  end
@@ -1,5 +1,6 @@
1
1
  en:
2
2
  minus: minus
3
+ dot: point
3
4
  single:
4
5
  0: zero
5
6
  1: one
data/yaml/support.yml CHANGED
@@ -9,3 +9,5 @@ support:
9
9
  natural:
10
10
  min: "-(10 ** 66) + 1"
11
11
  max: "(10 ** 66) - 1"
12
+ fractional:
13
+ symbols: 16
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.16
4
+ version: 0.2.17
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-24 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,8 @@ files:
62
62
  - lib/kabal/errors/no_support_for_fractional_numbers_on_current_language_error.rb
63
63
  - lib/kabal/errors/number_out_range_error.rb
64
64
  - lib/kabal/languages/english.rb
65
+ - lib/kabal/languages/english/fractional_numbers.rb
66
+ - lib/kabal/languages/english/natural_numbers.rb
65
67
  - lib/kabal/languages/language.rb
66
68
  - lib/kabal/languages/russian.rb
67
69
  - lib/kabal/languages/russian/declinations.rb