kabal 0.0.2 → 0.1.0

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: 4a95098432439efebdd18b4719132bf1c2ebfa9c
4
- data.tar.gz: b41d9d94671b75fdb212cc178e0f9f06ded2c35b
3
+ metadata.gz: c078ed5bdf068cd33cdc18e2a3d2f747fd7c6f53
4
+ data.tar.gz: 7b20723cdde68a9d8a0a33cc5f930c0e9687edcc
5
5
  SHA512:
6
- metadata.gz: 587ef89f29e52a3c17992e817246a958ac42111738091cc782b5baf35fcc33735b5e316568442ba54f7bab63db08b0f4cb60a621dc4156c8bc8a64e8740f6788
7
- data.tar.gz: b5f44d3d17f55fc17b8273325a690b8537b8b6d313c3c7344c95e849583ba133e421d70a0fd2d70c4b1573a52a1ceaefe02d37e1f87233aa046d3ad9a3f331fd
6
+ metadata.gz: a4f6b4480ebccefda786d77b0e9fb015a0b7283b8df5245c758314269c9d9d4ae9737fc142b318da2b736d70dd9a5725de92176785910ac29732a718a0967631
7
+ data.tar.gz: cec8bf534630fcd173a3262e482266be0707f8ee4aa51e92d607aaeda0bda876d1215cea1875df24a93601333a0dd39b168ae9cd789188715d1992ad2db5140b
data/kabal.gemspec CHANGED
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
22
23
  end
data/lib/kabal.rb CHANGED
@@ -1,12 +1,38 @@
1
1
  autoload :Version, "kabal/version"
2
2
  require "kabal/supported_languages"
3
+ require "kabal/errors"
3
4
  require 'yaml'
4
5
 
5
6
  module Kabal
6
7
  include SupportedLanguages
8
+ include Errors
7
9
 
8
10
  def to_text(number)
9
- rus = Russian.new
10
- rus.convert number
11
+ @language ||= "Russian"
12
+ obj = Object.const_get("Kabal::" + @language).new
13
+ obj.convert number
14
+ end
15
+
16
+ def language=(language_to_set)
17
+ languages = YAML.load_file('yaml/languages.yml')
18
+ if languages[language_to_set]
19
+ @language = language_to_set
20
+ else
21
+ raise NoLanguageSupportError.message
22
+ end
23
+ end
24
+
25
+ def to_text_in_language(number, language_at_once)
26
+ languages = YAML.load_file('yaml/languages.yml')
27
+ if languages[language_at_once]
28
+ obj = Object.const_get("Kabal::" + language_at_once).new
29
+ obj.convert number
30
+ else
31
+ raise NoLanguageSupportError.message
32
+ end
33
+ end
34
+
35
+ def current_language
36
+ @language
11
37
  end
12
38
  end
@@ -0,0 +1,4 @@
1
+ module Kabal::Errors
2
+ require "kabal/errors/no_language_support_error"
3
+ require "kabal/errors/number_out_range_error"
4
+ end
@@ -0,0 +1,5 @@
1
+ class Kabal::Errors::NoLanguageSupportError < StandardError
2
+ def self.message
3
+ "There is no support of such language yet"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Kabal::Errors::NumberOutRangeError < StandardError
2
+ def self.message
3
+ "Number is out of the range for current language"
4
+ end
5
+ end
@@ -2,6 +2,9 @@ require 'kabal/languages/language'
2
2
 
3
3
  class Kabal::Russian < Kabal::Language
4
4
  def convert(number)
5
+ #FIXME find way to get min and max from yml file
6
+ raise NumberOutRangeError.message if number < 0 or number >= 10 ** 102
7
+ #FIXME switch case next lines
5
8
  return single(number) if number >= 0 and number <= 19
6
9
  return two_words(number) if number >= 20 and number <= 99
7
10
  return three_words(number) if number >= 100 and number <= 999
data/lib/kabal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kabal
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class RussianTest < TestCase
4
+ def setup
5
+ @rus = Kabal::Russian.new
6
+ end
7
+
8
+ def test_to_text_with_single_number
9
+ assert_equal @rus.convert(1), "один"
10
+ end
11
+ def test_to_text_with_two_words_number
12
+ assert_equal @rus.convert(25), "двадцать пять"
13
+ end
14
+ def test_to_text_with_three_words_number
15
+ assert_equal @rus.convert(625), "шестьсот двадцать пять"
16
+ end
17
+ def test_to_text_with_ten_powers
18
+ assert_equal @rus.convert(125625), "сто двадцать пять тысяч шестьсот двадцать пять"
19
+ end
20
+ def test_to_text_with_ten_powers_millions
21
+ assert_equal @rus.convert(125125625), "сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
22
+ end
23
+ def test_to_text_with_ten_powers_some_number
24
+ assert_equal @rus.convert(1000001), "один миллион один"
25
+ end
26
+ def test_to_text_with_google
27
+ assert_equal @rus.convert(10 ** 100), "гугол"
28
+ end
29
+ def test_to_text_with_three_words_without_second_order
30
+ assert_equal @rus.convert(101), "сто один"
31
+ end
32
+ def test_to_text_with_three_words_without_first_and_second_order
33
+ assert_equal @rus.convert(200), "двести"
34
+ end
35
+ def test_to_text_with_thousands
36
+ assert_equal @rus.convert(22000), "двадцать две тысячи"
37
+ end
38
+ def test_to_text_with_negative_number
39
+ exception = assert_raises RuntimeError do
40
+ @rus.convert -1
41
+ end
42
+ assert_equal NumberOutRangeError.message, exception.message
43
+ end
44
+ end
@@ -3,34 +3,32 @@ require 'test_helper'
3
3
  include Kabal
4
4
 
5
5
  class KabalTest < TestCase
6
- def test_to_text_with_single_number
7
- assert_equal Kabal.to_text(1), "один"
6
+ def test_language_init
7
+ Kabal.language = "Russian"
8
+ assert_equal Kabal.current_language, "Russian"
8
9
  end
9
- def test_to_text_with_two_words_number
10
- assert_equal Kabal.to_text(25), "двадцать пять"
11
- end
12
- def test_to_text_with_three_words_number
13
- assert_equal Kabal.to_text(625), "шестьсот двадцать пять"
14
- end
15
- def test_to_text_with_ten_powers
16
- assert_equal Kabal.to_text(125625), "сто двадцать пять тысяч шестьсот двадцать пять"
17
- end
18
- def test_to_text_with_ten_powers_millions
19
- assert_equal Kabal.to_text(125125625), "сто двадцать пять миллионов сто двадцать пять тысяч шестьсот двадцать пять"
20
- end
21
- def test_to_text_with_ten_powers_some_number
22
- assert_equal Kabal.to_text(1000001), "один миллион один"
23
- end
24
- def test_to_text_with_google
25
- assert_equal Kabal.to_text(10 ** 100), "гугол"
10
+
11
+ def test_to_text
12
+ assert_equal Kabal.to_text(125125125125), "сто двадцать пять миллиардов сто двадцать пять миллионов сто двадцать пять тысяч сто двадцать пять"
26
13
  end
27
- def test_to_text_with_three_words_without_second_order
28
- assert_equal Kabal.to_text(101), "сто один"
14
+
15
+ def test_to_text_in_language
16
+ assert_equal Kabal.to_text_in_language(125125125125, "Russian"), "сто двадцать пять миллиардов сто двадцать пять миллионов сто двадцать пять тысяч сто двадцать пять"
29
17
  end
30
- def test_to_text_with_three_words_without_first_and_second_order
31
- assert_equal Kabal.to_text(200), "двести"
18
+
19
+ def test_to_text_in_language_with_unsupported_language
20
+ #FIXME replace RuntimeError to NoLanguageSupportError
21
+ exception = assert_raises RuntimeError do
22
+ Kabal.to_text_in_language(125125125125, "Elfin")
23
+ end
24
+ assert_equal NoLanguageSupportError.message, exception.message
32
25
  end
33
- def test_to_text_with_thousands
34
- assert_equal Kabal.to_text(22000), "двадцать две тысячи"
26
+
27
+ def test_language_init_with_unsupported_language
28
+ #FIXME replace RuntimeError to NoLanguageSupportError
29
+ exception = assert_raises RuntimeError do
30
+ Kabal.language = "Elfin"
31
+ end
32
+ assert_equal NoLanguageSupportError.message, exception.message
35
33
  end
36
34
  end
@@ -20,6 +20,9 @@ ru:
20
20
  17: семьнадцать
21
21
  18: восемьнадцать
22
22
  19: девятнадцать
23
+ single_feminine:
24
+ 1: одна
25
+ 2: две
23
26
  two_words:
24
27
  2: двадцать
25
28
  3: тридцать
@@ -76,6 +79,3 @@ ru:
76
79
  96: антригинтиллион
77
80
  99: дуотригинтиллион
78
81
  100: гугол
79
- single_feminine:
80
- 1: одна
81
- 2: две
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.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pavel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Kabal allows you to translate numbers into text.
28
42
  email:
29
43
  - kalashnikovisme@gmail.com
@@ -40,10 +54,14 @@ files:
40
54
  - Rakefile
41
55
  - kabal.gemspec
42
56
  - lib/kabal.rb
57
+ - lib/kabal/errors.rb
58
+ - lib/kabal/errors/no_language_support_error.rb
59
+ - lib/kabal/errors/number_out_range_error.rb
43
60
  - lib/kabal/languages/language.rb
44
61
  - lib/kabal/languages/russian.rb
45
62
  - lib/kabal/supported_languages.rb
46
63
  - lib/kabal/version.rb
64
+ - test/lib/kabal/languages/russian_test.rb
47
65
  - test/lib/kabal_test.rb
48
66
  - test/test_helper.rb
49
67
  - yaml/languages.yml
@@ -73,5 +91,6 @@ signing_key:
73
91
  specification_version: 4
74
92
  summary: Number To Text Helper
75
93
  test_files:
94
+ - test/lib/kabal/languages/russian_test.rb
76
95
  - test/lib/kabal_test.rb
77
96
  - test/test_helper.rb