kabal 0.1.5 → 0.1.6

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: d22c90bd40aac3a8ba178f098bba486a0bfc9d49
4
- data.tar.gz: 2e3f54d404fd4585828a8587c381e8d1ea29c250
3
+ metadata.gz: 3cf4b9fcfb470eb18a488ba782bdacd664767a3a
4
+ data.tar.gz: 8b6ad5bd552fdcb7cc42aff56039cac8991b85b4
5
5
  SHA512:
6
- metadata.gz: 9ac8dce387eae4fee82ee671cb233cea6bee2b3043423fe12f1b66a6279bf27ddfe23e6d2089fc0a29ef6b2a26efb8c89745cef73476e931757eee5a24bd5428
7
- data.tar.gz: 681ffb3be175372b594c56182b6cd3bcdcf2ab11babf0075c69fe1311f1e7c32f05cd4fbc8aa2688e328d82fc6700fdae19dbef0e7eeed73902d62be641b617c
6
+ metadata.gz: cf141f18e9a73bb9e03dd7998ca45c6855bb3259983b3a241b3d7c2bbaab86c67471144ac9a427df5501708589b9ba1de15ef498db08ad0e1828b87ea22d586a
7
+ data.tar.gz: cdcf93b6454fe22751d380b30a02892c693457bb84a1bb5795d851c54b2ae65bd9a3e609cb5222437ef25509476b423fe01186b5882c6fe2cd2cb16b6e8c93cb
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/kalashnikovisme/kabal.svg?branch=master)](https://travis-ci.org/kalashnikovisme/kabal)
4
4
  [![Coverage Status](https://coveralls.io/repos/kalashnikovisme/kabal/badge.png?branch=master)](https://coveralls.io/r/kalashnikovisme/kabal?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/kabal.svg)](http://badge.fury.io/rb/kabal)
6
+ [![endorse](https://api.coderwall.com/kalashnikovisme/endorsecount.png)](https://coderwall.com/kalashnikovisme)
5
7
 
6
8
  Kabal allows you to translate number into text.
7
9
 
@@ -8,5 +8,9 @@ module Kabal
8
8
  def names
9
9
  YamlLoader.yaml_object "languages/#{lang}"
10
10
  end
11
+
12
+ def minus
13
+ YamlLoader.yaml_object("languages/#{lang}")[lang]["minus"]
14
+ end
11
15
  end
12
16
  end
@@ -4,7 +4,13 @@ require 'kabal/languages/russian/declinations'
4
4
  class Kabal::Russian < Kabal::Language
5
5
  def convert(number)
6
6
  #FIXME find way to get min and max from yml file
7
- raise NumberOutRangeError.message if number < 0 or number >= 10 ** 102
7
+ raise NumberOutRangeError.message if number <= -(10 ** 102) or number >= 10 ** 102
8
+ #FIXME find better way
9
+ @number_name = nil
10
+ need_minus?(number) ? (minus + " " + natural_number_name(-number)) : natural_number_name(number)
11
+ end
12
+
13
+ def natural_number_name(number)
8
14
  #FIXME switch case next lines
9
15
  return single(number) if number >= 0 and number <= 19
10
16
  return two_words(number) if number >= 20 and number <= 99
@@ -12,6 +18,10 @@ class Kabal::Russian < Kabal::Language
12
18
  ten_powers(number) if number >= 1000
13
19
  end
14
20
 
21
+ def need_minus?(number)
22
+ number < 0
23
+ end
24
+
15
25
  def single(number)
16
26
  if @feminine_name_for_thousands
17
27
  @feminine_name_for_thousands = false
@@ -61,9 +71,7 @@ class Kabal::Russian < Kabal::Language
61
71
  end
62
72
 
63
73
  def less_thousands(number)
64
- unless number == 0
65
- @number_name += " " + three_words(number % 1000)
66
- end
74
+ @number_name += " " + three_words(number % 1000) unless number == 0
67
75
  end
68
76
 
69
77
  def number_is_thousands?(number)
@@ -1,3 +1,3 @@
1
1
  module Kabal
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -7,37 +7,47 @@ class RussianTest < TestCase
7
7
 
8
8
  def test_to_text_with_single_number
9
9
  assert_equal @rus.convert(1), "один"
10
+ assert_equal @rus.convert(-1), "минус один"
10
11
  end
11
12
  def test_to_text_with_two_words_number
12
13
  assert_equal @rus.convert(25), "двадцать пять"
14
+ assert_equal @rus.convert(-25), "минус двадцать пять"
13
15
  end
14
16
  def test_to_text_with_three_words_number
15
17
  assert_equal @rus.convert(625), "шестьсот двадцать пять"
18
+ assert_equal @rus.convert(-625), "минус шестьсот двадцать пять"
16
19
  end
17
20
  def test_to_text_with_ten_powers
18
21
  assert_equal @rus.convert(125625), "сто двадцать пять тысяч шестьсот двадцать пять"
22
+ assert_equal @rus.convert(-125625), "минус сто двадцать пять тысяч шестьсот двадцать пять"
19
23
  end
20
24
  def test_to_text_with_ten_powers_millions
21
25
  assert_equal @rus.convert(125125625), "сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
26
+ assert_equal @rus.convert(-125125625), "минус сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
22
27
  end
23
28
  def test_to_text_with_ten_powers_some_number
24
29
  assert_equal @rus.convert(1000001), "один миллион один"
30
+ assert_equal @rus.convert(-1000001), "минус один миллион один"
25
31
  end
26
32
  def test_to_text_with_google
27
33
  assert_equal @rus.convert(10 ** 100), "гугол"
34
+ assert_equal @rus.convert(-(10 ** 100)), "минус гугол"
28
35
  end
29
36
  def test_to_text_with_three_words_without_second_order
30
37
  assert_equal @rus.convert(101), "сто один"
38
+ assert_equal @rus.convert(-101), "минус сто один"
31
39
  end
32
40
  def test_to_text_with_three_words_without_first_and_second_order
33
41
  assert_equal @rus.convert(200), "двести"
42
+ assert_equal @rus.convert(-200), "минус двести"
34
43
  end
35
44
  def test_to_text_with_thousands
36
45
  assert_equal @rus.convert(22000), "двадцать две тысячи"
46
+ assert_equal @rus.convert(-22000), "минус двадцать две тысячи"
37
47
  end
38
48
  def test_to_text_with_negative_number
39
49
  exception = assert_raises RuntimeError do
40
- @rus.convert -1
50
+ @rus.convert -(10 ** 103)
41
51
  end
42
52
  assert_equal NumberOutRangeError.message, exception.message
43
53
  end
@@ -1,4 +1,5 @@
1
1
  ru:
2
+ minus: "минус"
2
3
  single:
3
4
  0: ноль
4
5
  1: один
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov