to_words 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmYwMzQyMTIwNDkzMWE5NjlkMjAzMGJhZTZmMDQ0YjNmYzQxOGEwOA==
5
- data.tar.gz: !binary |-
6
- NGVmMTA3NmI2NTdkZWU4OGM1YTM1YjhiNzA2MTg1YzY4NWY1ZDU1Mg==
2
+ SHA1:
3
+ metadata.gz: a13abac52d0e7ae6d0d5d3cbb3079d5c2ba167aa
4
+ data.tar.gz: 1538e9d9c7810c414108860fc5e6effcb741dedf
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWMxNjcxMzJjMGYwMDdkMTE0MzNlNjVkMmRhMDM4OTJlYTNkMmFlNzM5NzU3
10
- NDdlZmFhYTUwOGZjZTNjMzYyZGM3NjZkOGVlMTU5NWQ4ZGQzNWM0YzExYmVm
11
- NzkzOGNhMDYxOTQ4ZGMyNzFmOGFiOTBmZWI5YmI1ZjFiMTYyZTk=
12
- data.tar.gz: !binary |-
13
- MDEyOGViZGEyM2QyNTQxYWU0OGI4YmYyNTE5ZTU0NWExZTBmMDI5NmMyNzkw
14
- YWIzYjUwNWJhYmIwNDc2ZThkY2U4NTUwNTYxYjQ0N2I0MDg1MjZjNDI5N2Y0
15
- MDhhN2E1ZjRjZDljNTBlZDRkMjAxMTAxZmVmYmM2OWM4NGMyYWQ=
6
+ metadata.gz: c1de2b8f5d2a5f5b9ccd4ddb5ef7e0f8391f523c47bfac7aa99c120c6ef63b1e6f445e5f6e25675f1d554dda7210a102e8a2d8e034a5e6244811757fbed16282
7
+ data.tar.gz: e8dd6aefaa1ca5a357200e4e81ab8bf532da2e8ada5bd97fae99413e735caf8ffb3d62b41ce2cdb8ea3460cab18d00c9daaf569b28561873e8d9e4025de8afa6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ -fd
@@ -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 CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in to_words.gemspec
5
+ gem "coveralls", require: false
4
6
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
-
@@ -1,12 +1,16 @@
1
- require "to_words/version"
2
-
1
+ # frozen_string_literal: true
3
2
  module ToWords
3
+ require "to_words/version"
4
+ require_relative "./to_words/under_hundred.rb"
5
+ require_relative "./to_words/divisions.rb"
6
+ require_relative "./to_words/utils.rb"
4
7
 
5
- UNDER_HUNDRED = {""=>"", 0=>"zero", 1=>"one", 2=>"two", 3=>"three", 4=>"four", 5=>"five", 6=>"six", 7=>"seven", 8=>"eight", 9=>"nine", 10=>"ten", 11=>"eleven", 12=>"twelve", 13=>"thirteen", 14=>"fourteen", 15=>"fifteen", 16=>"sixteen", 17=>"seventeen", 18=>"eighteen", 19=>"nineteen", 20=>"twenty", 21=>"twenty one", 22=>"twenty two", 23=>"twenty three", 24=>"twenty four", 25=>"twenty five", 26=>"twenty six", 27=>"twenty seven", 28=>"twenty eight", 29=>"twenty nine", 30=>"thirty", 31=>"thirty one", 32=>"thirty two", 33=>"thirty three", 34=>"thirty four", 35=>"thirty five", 36=>"thirty six", 37=>"thirty seven", 38=>"thirty eight", 39=>"thirty nine", 40=>"forty", 41=>"forty one", 42=>"forty two", 43=>"forty three", 44=>"forty four", 45=>"forty five", 46=>"forty six", 47=>"forty seven", 48=>"forty eight", 49=>"forty nine", 50=>"fifty", 51=>"fifty one", 52=>"fifty two", 53=>"fifty three", 54=>"fifty four", 55=>"fifty five", 56=>"fifty six", 57=>"fifty seven", 58=>"fifty eight", 59=>"fifty nine", 60=>"sixty", 61=>"sixty one", 62=>"sixty two", 63=>"sixty three", 64=>"sixty four", 65=>"sixty five", 66=>"sixty six", 67=>"sixty seven", 68=>"sixty eight", 69=>"sixty nine", 70=>"seventy", 71=>"seventy one", 72=>"seventy two", 73=>"seventy three", 74=>"seventy four", 75=>"seventy five", 76=>"seventy six", 77=>"seventy seven", 78=>"seventy eight", 79=>"seventy nine", 80=>"eighty", 81=>"eighty one", 82=>"eighty two", 83=>"eighty three", 84=>"eighty four", 85=>"eighty five", 86=>"eighty six", 87=>"eighty seven", 88=>"eighty eight", 89=>"eighty nine", 90=>"ninety", 91=>"ninety one", 92=>"ninety two", 93=>"ninety three", 94=>"ninety four", 95=>"ninety five", 96=>"ninety six", 97=>"ninety seven", 98=>"ninety eight", 99=>"ninety nine", 100=>"one hundred"}
6
- DIVISIONS = ["", "Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintrillion"]
8
+ include ToWords::UnderHundred
9
+ include ToWords::Divisions
10
+ include ToWords::Utils
7
11
 
8
12
  def to_words
9
- num = self.to_i
13
+ num = numerical?(self)
10
14
  num, sign = check_sign(num)
11
15
  return (sign + UNDER_HUNDRED[num]) if num <= 100
12
16
  counter = 0
@@ -14,27 +18,18 @@ module ToWords
14
18
  while num != 0
15
19
  num, remaining = num.divmod(1000)
16
20
  temp_result = result_below_one_thousand(remaining, counter)
17
- result << temp_result + " " + DIVISIONS[counter] + " " if temp_result != ''
21
+ result << temp_result + " " + DIVISIONS[counter] + " " if temp_result
18
22
  counter += 1
19
23
  end
20
- return sign + result.reverse.join(", ").rstrip
21
- end
22
-
23
- def result_below_one_thousand(num, counter)
24
- hundred, remaining = num.divmod(100)
25
- return UNDER_HUNDRED[hundred] + " Hundred " + UNDER_HUNDRED[remaining] if hundred != 0 && remaining != 0 && counter != 0
26
- return UNDER_HUNDRED[hundred] + " Hundred and " + UNDER_HUNDRED[remaining] if hundred != 0 && remaining != 0
27
- return UNDER_HUNDRED[remaining] if hundred == 0 && remaining != 0
28
- return UNDER_HUNDRED[hundred] + " Hundred " if hundred != 0 && remaining == 0
29
- return ''
30
- end
31
-
32
- def check_sign(num)
33
- return num < 0 ? ([num.abs, 'negative ']) : ([num, ''])
24
+ sign + result.reverse.join(", ").rstrip
34
25
  end
35
26
  end
36
27
 
37
- class Fixnum
28
+ INTEGER_KLASS = 1.class # Fixnum before Ruby 2.4, Integer from Ruby 2.4
29
+ class INTEGER_KLASS
38
30
  include ToWords
39
31
  end
40
32
 
33
+ class String
34
+ include ToWords
35
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module ToWords
3
+ module Divisions
4
+ DIVISIONS = [
5
+ "",
6
+ "Thousand",
7
+ "Million",
8
+ "Billion",
9
+ "Trillion",
10
+ "Quadrillion",
11
+ "Quintrillion"
12
+ ].freeze
13
+ end
14
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+ module ToWords
3
+ module UnderHundred
4
+ UNDER_HUNDRED = {
5
+ 0 => "zero",
6
+ 1 => "one",
7
+ 2 => "two",
8
+ 3 => "three",
9
+ 4 => "four",
10
+ 5 => "five",
11
+ 6 => "six",
12
+ 7 => "seven",
13
+ 8 => "eight",
14
+ 9 => "nine",
15
+ 10 => "ten",
16
+ 11 => "eleven",
17
+ 12 => "twelve",
18
+ 13 => "thirteen",
19
+ 14 => "fourteen",
20
+ 15 => "fifteen",
21
+ 16 => "sixteen",
22
+ 17 => "seventeen",
23
+ 18 => "eighteen",
24
+ 19 => "nineteen",
25
+ 20 => "twenty",
26
+ 21 => "twenty one",
27
+ 22 => "twenty two",
28
+ 23 => "twenty three",
29
+ 24 => "twenty four",
30
+ 25 => "twenty five",
31
+ 26 => "twenty six",
32
+ 27 => "twenty seven",
33
+ 28 => "twenty eight",
34
+ 29 => "twenty nine",
35
+ 30 => "thirty",
36
+ 31 => "thirty one",
37
+ 32 => "thirty two",
38
+ 33 => "thirty three",
39
+ 34 => "thirty four",
40
+ 35 => "thirty five",
41
+ 36 => "thirty six",
42
+ 37 => "thirty seven",
43
+ 38 => "thirty eight",
44
+ 39 => "thirty nine",
45
+ 40 => "forty",
46
+ 41 => "forty one",
47
+ 42 => "forty two",
48
+ 43 => "forty three",
49
+ 44 => "forty four",
50
+ 45 => "forty five",
51
+ 46 => "forty six",
52
+ 47 => "forty seven",
53
+ 48 => "forty eight",
54
+ 49 => "forty nine",
55
+ 50 => "fifty",
56
+ 51 => "fifty one",
57
+ 52 => "fifty two",
58
+ 53 => "fifty three",
59
+ 54 => "fifty four",
60
+ 55 => "fifty five",
61
+ 56 => "fifty six",
62
+ 57 => "fifty seven",
63
+ 58 => "fifty eight",
64
+ 59 => "fifty nine",
65
+ 60 => "sixty",
66
+ 61 => "sixty one",
67
+ 62 => "sixty two",
68
+ 63 => "sixty three",
69
+ 64 => "sixty four",
70
+ 65 => "sixty five",
71
+ 66 => "sixty six",
72
+ 67 => "sixty seven",
73
+ 68 => "sixty eight",
74
+ 69 => "sixty nine",
75
+ 70 => "seventy",
76
+ 71 => "seventy one",
77
+ 72 => "seventy two",
78
+ 73 => "seventy three",
79
+ 74 => "seventy four",
80
+ 75 => "seventy five",
81
+ 76 => "seventy six",
82
+ 77 => "seventy seven",
83
+ 78 => "seventy eight",
84
+ 79 => "seventy nine",
85
+ 80 => "eighty",
86
+ 81 => "eighty one",
87
+ 82 => "eighty two",
88
+ 83 => "eighty three",
89
+ 84 => "eighty four",
90
+ 85 => "eighty five",
91
+ 86 => "eighty six",
92
+ 87 => "eighty seven",
93
+ 88 => "eighty eight",
94
+ 89 => "eighty nine",
95
+ 90 => "ninety",
96
+ 91 => "ninety one",
97
+ 92 => "ninety two",
98
+ 93 => "ninety three",
99
+ 94 => "ninety four",
100
+ 95 => "ninety five",
101
+ 96 => "ninety six",
102
+ 97 => "ninety seven",
103
+ 98 => "ninety eight",
104
+ 99 => "ninety nine",
105
+ 100 => "one hundred"
106
+ }.freeze
107
+ end
108
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./under_hundred.rb"
3
+ module ToWords
4
+ module Utils
5
+ include UnderHundred
6
+
7
+ def result_below_one_thousand(num, counter)
8
+ hundred, remaining = num.divmod(100)
9
+
10
+ return higher_than_hundred(hundred, remaining, counter) if hundred != 0
11
+ UNDER_HUNDRED[remaining] if hundred == 0 && remaining != 0
12
+ end
13
+
14
+ def higher_than_hundred(hundred, remaining, counter)
15
+ century = UNDER_HUNDRED[hundred]
16
+ if remaining != 0
17
+ return century + " Hundred " + UNDER_HUNDRED[remaining] if counter != 0
18
+ return century + " Hundred and " + UNDER_HUNDRED[remaining]
19
+ end
20
+ return century + " Hundred " if remaining == 0
21
+ end
22
+
23
+ def check_sign(num)
24
+ num < 0 ? [num.abs, "negative "] : [num, ""]
25
+ end
26
+
27
+ def numerical?(num)
28
+ Integer(num)
29
+ rescue
30
+ raise "A whole number is expected"
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ToWords
2
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
3
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_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,45 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../spec_helper"
3
+ RSpec.describe "DIVISIONS" do
4
+ let(:subject) do
5
+ ToWords::Divisions::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 "has Thousand at index 1" do
19
+ expect(subject[1]).to eq "Thousand"
20
+ end
21
+
22
+ it "has Million at index 2" do
23
+ expect(subject[2]).to eq "Million"
24
+ end
25
+
26
+ it "has Billion at index 3" do
27
+ expect(subject[3]).to eq "Billion"
28
+ end
29
+
30
+ it "has Trillion at index 4" do
31
+ expect(subject[4]).to eq "Trillion"
32
+ end
33
+
34
+ it "has Quadrillion at index 5" do
35
+ expect(subject[5]).to eq "Quadrillion"
36
+ end
37
+
38
+ it "has Quintrillion at index 6" do
39
+ expect(subject[6]).to eq "Quintrillion"
40
+ end
41
+
42
+ it "is expected to be frozen" do
43
+ expect(subject.frozen?).to be true
44
+ end
45
+ 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
+ ToWords::UnderHundred::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,30 @@
1
+ # frozen_string_literal: true
2
+ require_relative "spec_helper"
3
+ RSpec.describe "to_word" do
4
+ context '#to_word' do
5
+ it "converts 1 to `one`" do
6
+ expect(1.to_words).to eq("one")
7
+ end
8
+
9
+ it "converts '1' to `one`" do
10
+ expect("1".to_words).to eq("one")
11
+ end
12
+
13
+ it "converts '1,000' to `one`" do
14
+ expect(1_000.to_words).to eq("one Thousand")
15
+ end
16
+
17
+ it "raises error for non-numerical string '1d'" do
18
+ expect { "1d".to_words }.to raise_error "A whole number is expected"
19
+ end
20
+
21
+ it "raises error for non-numerical string 'd1'" do
22
+ expect { "d1".to_words }.to raise_error "A whole number is expected"
23
+ end
24
+
25
+ it "it extends Fixnum / Integer methods" do
26
+ # Fixnum before Ruby 2.4, Integer from Ruby 2.4
27
+ expect(1.methods).to include :to_words
28
+ end
29
+ end
30
+ end
@@ -1,15 +1,17 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'to_words/version'
5
+ require "to_words/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "to_words"
8
9
  spec.version = ToWords::VERSION
9
10
  spec.authors = ["Taimur Akhtar"]
10
11
  spec.email = ["taimur.akhtar@square63.com"]
11
- spec.summary = %q{This would convert numbers into words.}
12
- spec.description = %q{This gem would convert a number into its equivalent words(english).}
12
+ spec.summary = "This would convert numbers into words."
13
+ spec.description = "This gem would convert a number into its equivalent"\
14
+ " words(english)."
13
15
  spec.homepage = "https://github.com/taimur-akhtar/to_words"
14
16
  spec.license = "MIT"
15
17
 
@@ -20,4 +22,7 @@ Gem::Specification.new do |spec|
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.6"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rubocop"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry"
23
28
  end
metadata CHANGED
@@ -1,41 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taimur Akhtar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
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
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
82
  version: '0'
41
83
  description: This gem would convert a number into its equivalent words(english).
@@ -45,13 +87,22 @@ executables: []
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
- - .gitignore
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
49
93
  - Gemfile
50
94
  - LICENSE.txt
51
95
  - README.md
52
96
  - Rakefile
53
97
  - lib/to_words.rb
98
+ - lib/to_words/divisions.rb
99
+ - lib/to_words/under_hundred.rb
100
+ - lib/to_words/utils.rb
54
101
  - lib/to_words/version.rb
102
+ - spec/spec_helper.rb
103
+ - spec/to_words/division_spec.rb
104
+ - spec/to_words/under_hundred_spec.rb
105
+ - spec/to_words_spec.rb
55
106
  - to_words.gemspec
56
107
  homepage: https://github.com/taimur-akhtar/to_words
57
108
  licenses:
@@ -63,18 +114,22 @@ require_paths:
63
114
  - lib
64
115
  required_ruby_version: !ruby/object:Gem::Requirement
65
116
  requirements:
66
- - - ! '>='
117
+ - - ">="
67
118
  - !ruby/object:Gem::Version
68
119
  version: '0'
69
120
  required_rubygems_version: !ruby/object:Gem::Requirement
70
121
  requirements:
71
- - - ! '>='
122
+ - - ">="
72
123
  - !ruby/object:Gem::Version
73
124
  version: '0'
74
125
  requirements: []
75
126
  rubyforge_project:
76
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.6.8
77
128
  signing_key:
78
129
  specification_version: 4
79
130
  summary: This would convert numbers into words.
80
- test_files: []
131
+ test_files:
132
+ - spec/spec_helper.rb
133
+ - spec/to_words/division_spec.rb
134
+ - spec/to_words/under_hundred_spec.rb
135
+ - spec/to_words_spec.rb