to_russian_words 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 346812726e96d15239f6716e319645cf612fd2c2
4
- data.tar.gz: 2c260974caa40d84de6bf2ad29b1e7ccb8567266
3
+ metadata.gz: 76a4e11c1c88b6b6314f0aa1a3799fd43b505e7b
4
+ data.tar.gz: d4eaac1f43767afe425ec5eb99c570e32ce7d930
5
5
  SHA512:
6
- metadata.gz: 318b675911dcd1312837617dd05de09a45c758e9ff613fb24d691dc90238ed2b670270527dfa9e13bb9b443cf767e79acfbcacb67abb82bff68da70a2c3a3f8a
7
- data.tar.gz: dde4be3a41c0a2365e98eaa176bedbadca3fdc46cb16722bf02aa3276d118b56a0d3dd797fa71e14c82df0c3303420bfb63b6cbde7fafa3e0f5950a8ad9b46e6
6
+ metadata.gz: b69998d59c7a3e8327eda7a716be631aba75ec7db9a73663fade52d9516225fbeffd74b65221a1eaddfcb6c17e83cccdf93f4323845aec88557e4db59f829db9
7
+ data.tar.gz: 7a0545fba7c84714b0602e9cbc0348f55430e0133b232e18ac7f8d6316526c2bc10c5854ff39a1893fcb5a40fff08b5acb4b8c8a1f56b0c24742e57fdb0d69c9
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  module ToRussianWords
3
- require "to_russian_words/version"
4
- require_relative "./to_russian_words/under_hundred.rb"
5
- require_relative "./to_russian_words/divisions.rb"
6
- require_relative "./to_russian_words/utils.rb"
3
+ require 'to_russian_words/version'
4
+ require_relative './to_russian_words/under_hundred.rb'
5
+ require_relative './to_russian_words/divisions.rb'
6
+ require_relative './to_russian_words/utils.rb'
7
7
 
8
8
  include ToRussianWords::UnderHundred
9
9
  include ToRussianWords::Divisions
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module ToRussianWords
3
+ module RussianGenderLabels
4
+ NOMINATIVE_RUSSIAN_FEMALE_LABEL = [
5
+ '', 'одна', 'две'
6
+ ].freeze
7
+
8
+ DATIVE_RUSSIAN_FEMALE_LABEL = [
9
+ '', 'одной', 'двух'
10
+ ].freeze
11
+ end
12
+ end
@@ -1,24 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative './under_hundred.rb'
3
3
  require_relative "./divisions.rb"
4
+ require_relative "./russian_gender_labels.rb"
4
5
  module ToRussianWords
5
6
  module Utils
6
7
  include UnderHundred
7
8
  include Divisions
9
+ include RussianGenderLabels
8
10
 
9
11
  def result_below_one_thousand(num, counter, russian_case)
10
12
  hundred, remaining = num.divmod(100)
11
13
 
12
14
  return higher_than_hundred(hundred, remaining, counter, russian_case) if hundred != 0
13
- under_hundred(russian_case)[remaining] if hundred == 0 && remaining != 0
15
+ under_hundred(russian_case, counter == 1 ? num : nil)[remaining] if hundred == 0 && remaining != 0
14
16
  end
15
17
 
16
18
  def higher_than_hundred(hundred, remaining, counter, russian_case)
17
- century = (hundred == 1 ? '' : under_hundred(russian_case)[hundred])
19
+ century = (hundred == 1 ? '' : under_hundred(russian_case, hundred)[hundred])
18
20
  if remaining != 0
19
- return century + "#{hundred_name(russian_case, remaining)} " + under_hundred(russian_case)[remaining]
21
+ return century + "#{hundred_name(hundred, russian_case)} " + under_hundred(russian_case)[remaining]
20
22
  end
21
- return century + "#{hundred_name(russian_case, remaining)} " if remaining == 0
23
+ return century + "#{hundred_name(hundred, russian_case)} " if remaining == 0
22
24
  end
23
25
 
24
26
  def check_sign(num)
@@ -31,12 +33,12 @@ module ToRussianWords
31
33
  raise 'A whole number is expected'
32
34
  end
33
35
 
34
- def under_hundred(russian_case)
36
+ def under_hundred(russian_case, hundred = 0)
35
37
  case russian_case
36
38
  when 'dative'
37
- DATIVE_UNDER_HUNDRED
39
+ [1, 2].include?(hundred) ? DATIVE_RUSSIAN_FEMALE_LABEL : DATIVE_UNDER_HUNDRED
38
40
  else
39
- NOMINATIVE_UNDER_HUNDRED
41
+ [1, 2].include?(hundred) ? NOMINATIVE_RUSSIAN_FEMALE_LABEL : NOMINATIVE_UNDER_HUNDRED
40
42
  end
41
43
  end
42
44
 
@@ -49,19 +51,20 @@ module ToRussianWords
49
51
  end
50
52
  end
51
53
 
52
- def hundred_name(russian_case, remaining)
53
- remaining = remaining.to_s.last.to_i
54
+ def hundred_name(hundred, russian_case)
54
55
  case russian_case
55
56
  when 'dative'
56
- if remaining == 1
57
+ if hundred == 1
57
58
  'ста'
58
59
  else
59
60
  'сот'
60
61
  end
61
62
  else
62
- if remaining == 1
63
+ if [1, 4].include? hundred
63
64
  'сто'
64
- elsif remaining.between?(2, 4)
65
+ elsif hundred == 2
66
+ 'сти'
67
+ elsif hundred == 3
65
68
  'ста'
66
69
  else
67
70
  'сот'
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ToRussianWords
3
- VERSION = "1.1.2"
3
+ VERSION = '1.1.3'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_russian_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Gandzha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-25 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,6 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - lib/to_russian_words.rb
98
98
  - lib/to_russian_words/divisions.rb
99
+ - lib/to_russian_words/russian_gender_labels.rb
99
100
  - lib/to_russian_words/under_hundred.rb
100
101
  - lib/to_russian_words/utils.rb
101
102
  - lib/to_russian_words/version.rb