to_russian_words 1.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5af8092d6536adb922bb4c15e65f96e2da717638
4
+ data.tar.gz: a4535afdade520cb50907ef6d12627229b55de27
5
+ SHA512:
6
+ metadata.gz: c1a09a64c97b987f92662f8460fe3f71fff2f53bde458bef62ef2d76e361ba79b9e55ac2d2a49db35e6adbadcf8e59c6bbf260c4169a09180aeaa917d09bdbcb
7
+ data.tar.gz: 8a955db2e1a0740071258a834f8691a79bbda6d9effda6398c8a81cd6b044ac7e9ee8ec4429e0c060ab5669cb733cb5d08b0a309e0ca3c8d9d213c657e813efa
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ -fd
data/.rubocop.yml ADDED
@@ -0,0 +1,233 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ UseCache: false
4
+ Style/BracesAroundHashParameters:
5
+ EnforcedStyle: context_dependent
6
+ Style/CollectionMethods:
7
+ Description: Preferred collection methods.
8
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
9
+ Enabled: true
10
+ PreferredMethods:
11
+ collect: map
12
+ collect!: map!
13
+ find: detect
14
+ find_all: select
15
+ reduce: inject
16
+ Style/DotPosition:
17
+ Description: Checks the position of the dot in multi-line method calls.
18
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
19
+ Enabled: true
20
+ EnforcedStyle: trailing
21
+ SupportedStyles:
22
+ - leading
23
+ - trailing
24
+ Style/FileName:
25
+ Description: Use snake_case for source file names.
26
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
27
+ Enabled: false
28
+ Exclude: []
29
+ Style/GuardClause:
30
+ Description: Check for conditionals that can be replaced with guard clauses
31
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
32
+ Enabled: false
33
+ MinBodyLength: 1
34
+ Style/IfUnlessModifier:
35
+ Description: Favor modifier if/unless usage when you have a single-line body.
36
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
37
+ Enabled: false
38
+ MaxLineLength: 80
39
+ Style/OptionHash:
40
+ Description: Don't use option hashes when you can use keyword arguments.
41
+ Enabled: false
42
+ Style/PercentLiteralDelimiters:
43
+ Description: Use `%`-literal delimiters consistently
44
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
45
+ Enabled: false
46
+ PreferredDelimiters:
47
+ "%": "()"
48
+ "%i": "()"
49
+ "%q": "()"
50
+ "%Q": "()"
51
+ "%r": "{}"
52
+ "%s": "()"
53
+ "%w": "()"
54
+ "%W": "()"
55
+ "%x": "()"
56
+ Style/PredicateName:
57
+ Description: Check the names of predicate methods.
58
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
59
+ Enabled: true
60
+ NamePrefix:
61
+ - is_
62
+ - has_
63
+ - have_
64
+ NamePrefixBlacklist:
65
+ - is_
66
+ Exclude:
67
+ - spec/**/*
68
+ Style/RaiseArgs:
69
+ Description: Checks the arguments passed to raise/fail.
70
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
71
+ Enabled: false
72
+ EnforcedStyle: exploded
73
+ SupportedStyles:
74
+ - compact
75
+ - exploded
76
+ Style/SignalException:
77
+ Description: Checks for proper usage of fail and raise.
78
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
79
+ Enabled: false
80
+ EnforcedStyle: semantic
81
+ SupportedStyles:
82
+ - only_raise
83
+ - only_fail
84
+ - semantic
85
+ Style/SingleLineBlockParams:
86
+ Description: Enforces the names of some block params.
87
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
88
+ Enabled: false
89
+ Methods:
90
+ - reduce:
91
+ - a
92
+ - e
93
+ - inject:
94
+ - a
95
+ - e
96
+ Style/SingleLineMethods:
97
+ Description: Avoid single-line methods.
98
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
99
+ Enabled: false
100
+ AllowIfMethodIsEmpty: true
101
+ Style/StringLiterals:
102
+ Description: Checks if uses of quotes match the configured preference.
103
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
104
+ Enabled: true
105
+ EnforcedStyle: double_quotes
106
+ SupportedStyles:
107
+ - single_quotes
108
+ - double_quotes
109
+ Style/StringLiteralsInInterpolation:
110
+ Description: Checks if uses of quotes inside expressions in interpolated strings
111
+ match the configured preference.
112
+ Enabled: true
113
+ EnforcedStyle: single_quotes
114
+ SupportedStyles:
115
+ - single_quotes
116
+ - double_quotes
117
+ Style/TrailingCommaInLiteral:
118
+ Description: Checks for trailing comma in parameter lists and literals.
119
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
120
+ Enabled: false
121
+ EnforcedStyleForMultiline: no_comma
122
+ SupportedStyles:
123
+ - comma
124
+ - no_comma
125
+ Metrics/AbcSize:
126
+ Description: A calculated magnitude based on number of assignments, branches, and
127
+ conditions.
128
+ Enabled: false
129
+ Max: 15
130
+ Metrics/ClassLength:
131
+ Description: Avoid classes longer than 100 lines of code.
132
+ Enabled: false
133
+ CountComments: false
134
+ Max: 100
135
+ Metrics/ModuleLength:
136
+ CountComments: false
137
+ Max: 100
138
+ Description: Avoid modules longer than 100 lines of code.
139
+ Enabled: false
140
+ Metrics/CyclomaticComplexity:
141
+ Description: A complexity metric that is strongly correlated to the number of test
142
+ cases needed to validate a method.
143
+ Enabled: false
144
+ Max: 6
145
+ Metrics/MethodLength:
146
+ Description: Avoid methods longer than 10 lines of code.
147
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
148
+ Enabled: false
149
+ CountComments: false
150
+ Max: 10
151
+ Metrics/ParameterLists:
152
+ Description: Avoid parameter lists longer than three or four parameters.
153
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
154
+ Enabled: false
155
+ Max: 5
156
+ CountKeywordArgs: true
157
+ Metrics/PerceivedComplexity:
158
+ Description: A complexity metric geared towards measuring complexity for a human
159
+ reader.
160
+ Enabled: false
161
+ Max: 7
162
+ Lint/AssignmentInCondition:
163
+ Description: Don't use assignment in conditions.
164
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
165
+ Enabled: false
166
+ AllowSafeAssignment: true
167
+ Style/InlineComment:
168
+ Description: Avoid inline comments.
169
+ Enabled: false
170
+ Style/AccessorMethodName:
171
+ Description: Check the naming of accessor methods for get_/set_.
172
+ Enabled: false
173
+ Style/Alias:
174
+ Description: Use alias_method instead of alias.
175
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
176
+ Enabled: false
177
+ Style/Documentation:
178
+ Description: Document classes and non-namespace modules.
179
+ Enabled: false
180
+ Style/DoubleNegation:
181
+ Description: Checks for uses of double negation (!!).
182
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
183
+ Enabled: false
184
+ Style/EachWithObject:
185
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
186
+ Enabled: false
187
+ Style/EmptyLiteral:
188
+ Description: Prefer literals to Array.new/Hash.new/String.new.
189
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
190
+ Enabled: false
191
+ Style/ModuleFunction:
192
+ Description: Checks for usage of `extend self` in modules.
193
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
194
+ Enabled: false
195
+ Style/OneLineConditional:
196
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
197
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
198
+ Enabled: false
199
+ Style/PerlBackrefs:
200
+ Description: Avoid Perl-style regex back references.
201
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
202
+ Enabled: false
203
+ Style/Send:
204
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
205
+ may overlap with existing methods.
206
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
207
+ Enabled: false
208
+ Style/SpecialGlobalVars:
209
+ Description: Avoid Perl-style global variables.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
211
+ Enabled: false
212
+ Style/VariableInterpolation:
213
+ Description: Don't interpolate global, instance and class variables directly in
214
+ strings.
215
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
216
+ Enabled: false
217
+ Style/WhenThen:
218
+ Description: Use when x then ... for one-line cases.
219
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
220
+ Enabled: false
221
+ Lint/EachWithObjectArgument:
222
+ Description: Check for immutable argument given to each_with_object.
223
+ Enabled: true
224
+ Lint/HandleExceptions:
225
+ Description: Don't suppress exception.
226
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
227
+ Enabled: false
228
+ Lint/LiteralInCondition:
229
+ Description: Checks of literals used in conditions.
230
+ Enabled: false
231
+ Lint/LiteralInInterpolation:
232
+ Description: Checks for literals used in interpolation.
233
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ # Specify your gem's dependencies in to_russian_words.gemspec
5
+ gem "coveralls", require: false
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Taimur Akhtar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ToWords
2
+
3
+ This Gem converts numbers into words.
4
+
5
+ e.g.
6
+
7
+ 25.to_words('dative') # "двадцати пяти"
8
+ 70.to_words('dative') # "семидесяти"
9
+ 70.to_words() # "семьдесят"
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'to_words', git: 'git://github.com/VasiliyG/to_words.git', tag: 'v1.0.7'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/VasiliyG/to_words/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
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"
7
+
8
+ include ToRussianWords::UnderHundred
9
+ include ToRussianWords::Divisions
10
+ include ToRussianWords::Utils
11
+
12
+ def to_words(russian_case = 'nominative')
13
+ to_russian_words(russian_case)
14
+ end
15
+
16
+ def to_russian_words(russian_case = 'nominative')
17
+ num = numerical?(self)
18
+ num, sign = check_sign(num)
19
+ return (sign + under_hundred(russian_case)[num]) if num <= 100
20
+ counter = 0
21
+ result = []
22
+ while num != 0
23
+ num, remaining = num.divmod(1000)
24
+ temp_result = result_below_one_thousand(remaining, counter, russian_case)
25
+ result << temp_result + ' ' + divisions(russian_case)[counter] + ' ' if temp_result
26
+ counter += 1
27
+ end
28
+ sign + result.reverse.join(' ').rstrip
29
+ end
30
+ end
31
+
32
+ INTEGER_KLASS = 1.class # Fixnum before Ruby 2.4, Integer from Ruby 2.4
33
+ class INTEGER_KLASS
34
+ include ToRussianWords
35
+ end
36
+
37
+ class String
38
+ include ToRussianWords
39
+ end
40
+
41
+ class Fixnum
42
+ include ToRussianWords
43
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module ToRussianWords
3
+ module Divisions
4
+ NOMINATIVE_DIVISIONS = [
5
+ '',
6
+ 'тысяч',
7
+ 'миллион',
8
+ 'миллиард',
9
+ 'триллион',
10
+ 'квадрильон',
11
+ 'нониллион'
12
+ ].freeze
13
+
14
+ DATIVE_DIVISIONS = [
15
+ '',
16
+ 'тысячи',
17
+ 'миллиона',
18
+ 'миллиарда',
19
+ 'триллиона',
20
+ 'квадрильона',
21
+ 'нониллиона'
22
+ ].freeze
23
+ end
24
+ end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+ module ToRussianWords
3
+ module UnderHundred
4
+ NOMINATIVE_UNDER_HUNDRED = {
5
+ 0 => "ноль",
6
+ 1 => "один",
7
+ 2 => "два",
8
+ 3 => "три",
9
+ 4 => "четыре",
10
+ 5 => "пять",
11
+ 6 => "шесть",
12
+ 7 => "семь",
13
+ 8 => "восемь",
14
+ 9 => "девять",
15
+ 10 => "десять",
16
+ 11 => "одиннадцать",
17
+ 12 => "двенадцать",
18
+ 13 => "тринадцать",
19
+ 14 => "четырнадцать",
20
+ 15 => "пятьнадцать",
21
+ 16 => "шестьнадцать",
22
+ 17 => "семьнадцать",
23
+ 18 => "восемьнадцать",
24
+ 19 => "девятьнадцать",
25
+ 20 => "двадцать",
26
+ 21 => "двадцать один",
27
+ 22 => "двадцать два",
28
+ 23 => "двадцать три",
29
+ 24 => "двадцать четыре",
30
+ 25 => "двадцать пять",
31
+ 26 => "двадцать шесть",
32
+ 27 => "двадцать семь",
33
+ 28 => "двадцать восемь",
34
+ 29 => "двадцать девять",
35
+ 30 => "тридцать",
36
+ 31 => "тридцать один",
37
+ 32 => "тридцать два",
38
+ 33 => "тридцать три",
39
+ 34 => "тридцать четыре",
40
+ 35 => "тридцать пять",
41
+ 36 => "тридцать шесть",
42
+ 37 => "тридцать семь",
43
+ 38 => "тридцать восемь",
44
+ 39 => "тридцать девять",
45
+ 40 => "сорок",
46
+ 41 => "сорок один",
47
+ 42 => "сорок два",
48
+ 43 => "сорок три",
49
+ 44 => "сорок четыре",
50
+ 45 => "сорок пять",
51
+ 46 => "сорок шесть",
52
+ 47 => "сорок семь",
53
+ 48 => "сорок восемь",
54
+ 49 => "сорок девять",
55
+ 50 => "пятьдесят",
56
+ 51 => "пятьдесят один",
57
+ 52 => "пятьдесят два",
58
+ 53 => "пятьдесят три",
59
+ 54 => "пятьдесят четыре",
60
+ 55 => "пятьдесят пять",
61
+ 56 => "пятьдесят шесть",
62
+ 57 => "пятьдесят семь",
63
+ 58 => "пятьдесят восемь",
64
+ 59 => "пятьдесят девять",
65
+ 60 => "шестьдесят",
66
+ 61 => "шестьдесят один",
67
+ 62 => "шестьдесят два",
68
+ 63 => "шестьдесят три",
69
+ 64 => "шестьдесят четыре",
70
+ 65 => "шестьдесят пять",
71
+ 66 => "шестьдесят шесть",
72
+ 67 => "шестьдесят семь",
73
+ 68 => "шестьдесят восемь",
74
+ 69 => "шестьдесят девять",
75
+ 70 => "семьдесят",
76
+ 71 => "семьдесят один",
77
+ 72 => "семьдесят два",
78
+ 73 => "семьдесят три",
79
+ 74 => "семьдесят четыре",
80
+ 75 => "семьдесят пять",
81
+ 76 => "семьдесят шесть",
82
+ 77 => "семьдесят семь",
83
+ 78 => "семьдесят восемь",
84
+ 79 => "семьдесят девять",
85
+ 80 => "восемьдесят",
86
+ 81 => "восемьдесят один",
87
+ 82 => "восемьдесят два",
88
+ 83 => "восемьдесят три",
89
+ 84 => "восемьдесят четыре",
90
+ 85 => "восемьдесят пять",
91
+ 86 => "восемьдесят шесть",
92
+ 87 => "восемьдесят семь",
93
+ 88 => "восемьдесят восемь",
94
+ 89 => "восемьдесят девять",
95
+ 90 => "девяносто",
96
+ 91 => "девяносто один",
97
+ 92 => "девяносто два",
98
+ 93 => "девяносто три",
99
+ 94 => "девяносто четыре",
100
+ 95 => "девяносто пять",
101
+ 96 => "девяносто шесть",
102
+ 97 => "девяносто семь",
103
+ 98 => "девяносто восемь",
104
+ 99 => "девяносто девять",
105
+ 100 => "сто"
106
+ }.freeze
107
+
108
+ DATIVE_UNDER_HUNDRED = {
109
+ 0 => "нуля",
110
+ 1 => "одного",
111
+ 2 => "двух",
112
+ 3 => "трех",
113
+ 4 => "четырех",
114
+ 5 => "пяти",
115
+ 6 => "шести",
116
+ 7 => "семи",
117
+ 8 => "восьми",
118
+ 9 => "девяти",
119
+ 10 => "десяти",
120
+ 11 => "одиннадцати",
121
+ 12 => "двенадцати",
122
+ 13 => "тринадцати",
123
+ 14 => "четырнадцати",
124
+ 15 => "пятьнадцати",
125
+ 16 => "шестьнадцати",
126
+ 17 => "семьнадцати",
127
+ 18 => "восемьнадцати",
128
+ 19 => "девятьнадцати",
129
+ 20 => "двадцати",
130
+ 21 => "двадцати одного",
131
+ 22 => "двадцати двух",
132
+ 23 => "двадцати трех",
133
+ 24 => "двадцати четырех",
134
+ 25 => "двадцати пяти",
135
+ 26 => "двадцати шести",
136
+ 27 => "двадцати семи",
137
+ 28 => "двадцати восьми",
138
+ 29 => "двадцати девяти",
139
+ 30 => "тридцати",
140
+ 31 => "тридцати одного",
141
+ 32 => "тридцати двух",
142
+ 33 => "тридцати трех",
143
+ 34 => "тридцати четырех",
144
+ 35 => "тридцати пяти",
145
+ 36 => "тридцати шести",
146
+ 37 => "тридцати семи",
147
+ 38 => "тридцати восьми",
148
+ 39 => "тридцати девяти",
149
+ 40 => "сорока",
150
+ 41 => "сорока одного",
151
+ 42 => "сорока двух",
152
+ 43 => "сорока трех",
153
+ 44 => "сорока четырех",
154
+ 45 => "сорока пяти",
155
+ 46 => "сорока шести",
156
+ 47 => "сорока семи",
157
+ 48 => "сорока восьми",
158
+ 49 => "сорока девяти",
159
+ 50 => "пятидесяти",
160
+ 51 => "пятидесяти одного",
161
+ 52 => "пятидесяти двух",
162
+ 53 => "пятидесяти трех",
163
+ 54 => "пятидесяти четырех",
164
+ 55 => "пятидесяти пяти",
165
+ 56 => "пятидесяти шести",
166
+ 57 => "пятидесяти семи",
167
+ 58 => "пятидесяти восьми",
168
+ 59 => "пятидесяти девяти",
169
+ 60 => "шестидесяти",
170
+ 61 => "шестидесяти одного",
171
+ 62 => "шестидесяти двух",
172
+ 63 => "шестидесяти трех",
173
+ 64 => "шестидесяти четырех",
174
+ 65 => "шестидесяти пяти",
175
+ 66 => "шестидесяти шести",
176
+ 67 => "шестидесяти семи",
177
+ 68 => "шестидесяти восьми",
178
+ 69 => "шестидесяти девяти",
179
+ 70 => "семидесяти",
180
+ 71 => "семидесяти одного",
181
+ 72 => "семидесяти двух",
182
+ 73 => "семидесяти трех",
183
+ 74 => "семидесяти четырех",
184
+ 75 => "семидесяти пяти",
185
+ 76 => "семидесяти шести",
186
+ 77 => "семидесяти семи",
187
+ 78 => "семидесяти восьми",
188
+ 79 => "семидесяти девяти",
189
+ 80 => "восьмидесяти",
190
+ 81 => "восьмидесяти одного",
191
+ 82 => "восьмидесяти двух",
192
+ 83 => "восьмидесяти трех",
193
+ 84 => "восьмидесяти четырех",
194
+ 85 => "восьмидесяти пяти",
195
+ 86 => "восьмидесяти шести",
196
+ 87 => "восьмидесяти семи",
197
+ 88 => "восьмидесяти восьми",
198
+ 89 => "восьмидесяти девяти",
199
+ 90 => "девяноста",
200
+ 91 => "девяноста одного",
201
+ 92 => "девяноста двух",
202
+ 93 => "девяноста трех",
203
+ 94 => "девяноста четырех",
204
+ 95 => "девяноста пяти",
205
+ 96 => "девяноста шести",
206
+ 97 => "девяноста семи",
207
+ 98 => "девяноста восьми",
208
+ 99 => "девяноста девяти",
209
+ 100 => "ста"
210
+ }.freeze
211
+ end
212
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ require_relative './under_hundred.rb'
3
+ require_relative "./divisions.rb"
4
+ module ToRussianWords
5
+ module Utils
6
+ include UnderHundred
7
+ include Divisions
8
+
9
+ def result_below_one_thousand(num, counter, russian_case)
10
+ hundred, remaining = num.divmod(100)
11
+
12
+ return higher_than_hundred(hundred, remaining, counter, russian_case) if hundred != 0
13
+ under_hundred(russian_case)[remaining] if hundred == 0 && remaining != 0
14
+ end
15
+
16
+ def higher_than_hundred(hundred, remaining, counter, russian_case)
17
+ century = under_hundred(russian_case)[hundred]
18
+ if remaining != 0
19
+ return century + "#{hundred_name(russian_case)} " + under_hundred(russian_case)[remaining]
20
+ end
21
+ return century + "#{hundred_name(russian_case)} " if remaining == 0
22
+ end
23
+
24
+ def check_sign(num)
25
+ num < 0 ? [num.abs, 'negative '] : [num, '']
26
+ end
27
+
28
+ def numerical?(num)
29
+ Integer(num)
30
+ rescue
31
+ raise 'A whole number is expected'
32
+ end
33
+
34
+ def under_hundred(russian_case)
35
+ case russian_case
36
+ when 'dative'
37
+ DATIVE_UNDER_HUNDRED
38
+ else
39
+ NOMINATIVE_UNDER_HUNDRED
40
+ end
41
+ end
42
+
43
+ def divisions(russian_case)
44
+ case russian_case
45
+ when 'dative'
46
+ DATIVE_DIVISIONS
47
+ else
48
+ NOMINATIVE_DIVISIONS
49
+ end
50
+ end
51
+
52
+ def hundred_name(russian_case)
53
+ case russian_case
54
+ when 'dative'
55
+ 'сот'
56
+ else
57
+ 'ста'
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module ToRussianWords
3
+ VERSION = "1.1.1"
4
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require "coveralls"
3
+ Coveralls.wear!
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+ require "to_russian_words"
6
+ require "pry"
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |expectations|
9
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
10
+ end
11
+
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.verify_partial_doubles = true
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require_relative "spec_helper"
3
+ RSpec.describe "to_russian_word" do
4
+ context "#to_word" do
5
+ it "converts 1 to `one`" do
6
+ expect(1.to_russian_words).to eq("один")
7
+ end
8
+
9
+ it "converts '1' to `one`" do
10
+ expect("1".to_russian_words).to eq("один")
11
+ end
12
+
13
+ it "raises error for non-numerical string '1d'" do
14
+ expect { "1d".to_russian_words }.to raise_error "A whole number is expected"
15
+ end
16
+
17
+ it "raises error for non-numerical string 'd1'" do
18
+ expect { "d1".to_russian_words }.to raise_error "A whole number is expected"
19
+ end
20
+
21
+ it "it extends Fixnum / Integer methods" do
22
+ # Fixnum before Ruby 2.4, Integer from Ruby 2.4
23
+ expect(1.methods).to include :to_russian_words
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../spec_helper"
3
+ RSpec.describe "DIVISIONS" do
4
+ let(:subject) do
5
+ ToRussianWords::Divisions::NOMINATIVE_DIVISIONS
6
+ end
7
+
8
+ it { is_expected.to be_a Array }
9
+
10
+ it "has 7 items" do
11
+ expect(subject.length).to eq 7
12
+ end
13
+
14
+ it "has '' at index 0" do
15
+ expect(subject[0]).to eq ""
16
+ end
17
+
18
+ it "is expected to be frozen" do
19
+ expect(subject.frozen?).to be true
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../spec_helper"
3
+ RSpec.describe "UNDER_HUNDRED" do
4
+ let(:subject) do
5
+ ToRussianWords::UnderHundred::NOMINATIVE_UNDER_HUNDRED
6
+ end
7
+
8
+ it { is_expected.to be_a Hash }
9
+
10
+ it "has all keys to be integers" do
11
+ integer_class = 1.class # Fixnum before Ruby 2.4, Integer from Ruby 2.4
12
+ expect(subject.keys.all? { |key| key.is_a? integer_class }).to be true
13
+ end
14
+
15
+ it "has all values to be strings" do
16
+ expect(subject.values.all? { |value| value.is_a? String }).to be true
17
+ end
18
+
19
+ it "is expected to be frozen" do
20
+ expect(subject.frozen?).to be true
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "to_russian_words/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "to_russian_words"
9
+ spec.version = ToRussianWords::VERSION
10
+ spec.authors = ["Vasiliy Gandzha"]
11
+ spec.email = ["vasivik@vasivik.ru"]
12
+ spec.summary = "This would convert numbers into russian words."
13
+ spec.description = "This gem would convert a number into its equivalent"\
14
+ " words(russian)."
15
+ spec.homepage = "https://github.com/VasiliyG/to_russian_words"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rubocop"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry"
28
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_russian_words
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Vasiliy Gandzha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem would convert a number into its equivalent words(russian).
84
+ email:
85
+ - vasivik@vasivik.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/to_russian_words.rb
98
+ - lib/to_russian_words/divisions.rb
99
+ - lib/to_russian_words/under_hundred.rb
100
+ - lib/to_russian_words/utils.rb
101
+ - lib/to_russian_words/version.rb
102
+ - spec/spec_helper.rb
103
+ - spec/to_russiam_words_spec.rb
104
+ - spec/to_russian_words/division_spec.rb
105
+ - spec/to_russian_words/under_hundred_spec.rb
106
+ - to_russian_words.gemspec
107
+ homepage: https://github.com/VasiliyG/to_russian_words
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.8
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: This would convert numbers into russian words.
131
+ test_files:
132
+ - spec/spec_helper.rb
133
+ - spec/to_russiam_words_spec.rb
134
+ - spec/to_russian_words/division_spec.rb
135
+ - spec/to_russian_words/under_hundred_spec.rb