suckysockets 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README +16 -0
- data/bin/suckysockets +10 -0
- data/lib/sucky_socket/countries_sockets_plugs.rb +306 -0
- data/lib/sucky_socket/country.rb +56 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/sucky_socket/countries_sockets_plugs_spec.rb +19 -0
- data/spec/sucky_socket/country_spec.rb +88 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1be8f3cf8b93a3c28026ede0e979e1dbfcac123e2ce062b67a5eea5e9a65861e
|
4
|
+
data.tar.gz: 37491a87f4f95ef28f789ed978a4b894a0c74dbd046e534e08fbe4fde24c2733
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b64b66ca3d572732c50ccc80408679f3e820690ade60640c48191cc864233855e96ea287cc5533a8f79c809243ab70ca63efc8992ce11f80a8f6887f0a56926e
|
7
|
+
data.tar.gz: 8e9639176e70b757b9c2cae0f87de15d0a4468834f2d8c235ee1ab0e2630e9e1ea3eb4a96a6603732e4b1d006816fb0afd1a10ea8c9b4cfb7b775d729218f2d5
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2023 BluePeony
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
The suckysockets gem provides the user with the opportunity to check whether a power adapter is needed when travelling from one country to another.
|
2
|
+
|
3
|
+
1. How to install the gem
|
4
|
+
gem install suckysockets
|
5
|
+
|
6
|
+
2. How to use it
|
7
|
+
To run the program just type 'suckysockets' in the command line.
|
8
|
+
|
9
|
+
You will be asked in which country you currently live. Please type the country name and press 'enter'.
|
10
|
+
Next you need to enter your destination country and press 'enter' again.
|
11
|
+
Then you receive the result telling you whether or nor you need an adapter travelling from you current country to the destination country.
|
12
|
+
|
13
|
+
Three outcomes are possible:
|
14
|
+
- an adapter is not needed. That is the case when all plugs common in your country of living fit all of the sockets in your destination country.
|
15
|
+
- an adapter is definetely needed. That is the case when none of the plugs in your home country fit any of the sockets in your destination country.
|
16
|
+
- an adapter is needed in certain cases: when some of your home country plugs fit some of the sockets, but some plugs don't. In that case you will get a detailed response telling you for which particular cases an adapter is needed.
|
data/bin/suckysockets
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/sucky_socket/country'
|
4
|
+
|
5
|
+
puts "In which country do you live?"
|
6
|
+
start_country = SuckySocket::Country.new(gets.chomp)
|
7
|
+
puts "What is your destination country?"
|
8
|
+
destination_country = SuckySocket::Country.new(gets.chomp)
|
9
|
+
|
10
|
+
start_country.needs_adapter_for?(destination_country)
|
@@ -0,0 +1,306 @@
|
|
1
|
+
module SuckySocket
|
2
|
+
module CountriesSocketsPlugs
|
3
|
+
|
4
|
+
# this hash with country name as the key and an array of sockets that are used in this country
|
5
|
+
COUNTRIES_SOCKETS = {
|
6
|
+
"Abu Dhabi" => %i(G),
|
7
|
+
"Afghanistan" => %i(C F),
|
8
|
+
"Aland Islands" => %i(C F),
|
9
|
+
"Albania" => %i(C F),
|
10
|
+
"Algeria" => %i(C F),
|
11
|
+
"American Samoa" => %i(A B F I),
|
12
|
+
"Andorra" => %i(C F),
|
13
|
+
"Angola" => %i(C F),
|
14
|
+
"Anguilla" => %i(A B),
|
15
|
+
"Antigua And Barbuda" => %i(A B),
|
16
|
+
"Argentina" => %i(C I),
|
17
|
+
"Armenia" => %i(C F),
|
18
|
+
"Aruba" => %i(A B F),
|
19
|
+
"Australia" => %i(I),
|
20
|
+
"Austria" => %i(C F),
|
21
|
+
"Azerbaijan" => %i(C F),
|
22
|
+
"Azores" => %i(A B C F),
|
23
|
+
"Bahamas" => %i(A B),
|
24
|
+
"Bahrain" => %i(G),
|
25
|
+
"Balearic Island" => %i(C F),
|
26
|
+
"Bangladesh" => %i(A C D G),
|
27
|
+
"Barbados" => %i(A B),
|
28
|
+
"Belarus" => %i(C F),
|
29
|
+
"Belgium" => %i(C E),
|
30
|
+
"Belize" => %i(A B G),
|
31
|
+
"Benin" => %i(C E),
|
32
|
+
"Bermuda" => %i(A B),
|
33
|
+
"Bhutan" => %i(C D G),
|
34
|
+
"Bolivia" => %i(A C),
|
35
|
+
"Bonaire" => %i(A C),
|
36
|
+
"Bosnia and Herzegowina" => %i(C F),
|
37
|
+
"Botswana" => %i(D G),
|
38
|
+
"Brazil" => %i(C N),
|
39
|
+
"British Indian Ocean Territory" => %i(A B),
|
40
|
+
"British Virgin Islands" => %i(A B),
|
41
|
+
"Brunei" => %i(G),
|
42
|
+
"Bulgaria" => %i(C F),
|
43
|
+
"Burkina Faso" => %i(C E),
|
44
|
+
"Burundi" => %i(C E),
|
45
|
+
"Cambodia" => %i(A C G),
|
46
|
+
"Cameroon" => %i(C E),
|
47
|
+
"Canada" => %i(A B),
|
48
|
+
"Canary Islands" => %i(C E F),
|
49
|
+
"Cape Verde" => %i(C F),
|
50
|
+
"Cayman Islands" => %i(A B),
|
51
|
+
"Central African Republic" => %i(C E),
|
52
|
+
"Chad" => %i(C E F),
|
53
|
+
"Channel Islands" => %i(C G),
|
54
|
+
"Chile" => %i(C L),
|
55
|
+
"China" => %i(A C I),
|
56
|
+
"Christmas Island" => %i(I),
|
57
|
+
"Cocos (Keeling) Islands" => %i(I),
|
58
|
+
"Colombia" => %i(A B),
|
59
|
+
"Comoros" => %i(C E),
|
60
|
+
"Congo-Brazzaville" => %i(C E),
|
61
|
+
"Congo-Kinshasa" => %i(C E),
|
62
|
+
"Cook Islands" => %i(I),
|
63
|
+
"Costa Rica" => %i(A B),
|
64
|
+
"Cote d'Ivoire" => %i(C E),
|
65
|
+
"Croatia" => %i(C F),
|
66
|
+
"Cuba" => %i(A B C L),
|
67
|
+
"Curaçao" => %i(A B),
|
68
|
+
"Cyprus" => %i(G),
|
69
|
+
"Czech Republic" => %i(C E),
|
70
|
+
"Denmark" => %i(C E F K),
|
71
|
+
"Djibouti" => %i(C E),
|
72
|
+
"Dominica" => %i(D G),
|
73
|
+
"Dominican Republic" => %i(A B C),
|
74
|
+
"Dubai" => %i(G),
|
75
|
+
"East-Timor" => %i(C E F I),
|
76
|
+
"Ecuador" => %i(A B),
|
77
|
+
"Egypt" => %i(C F),
|
78
|
+
"El Salvador" => %i(A B),
|
79
|
+
"England" => %i(G),
|
80
|
+
"Equatorial Guinea" => %i(C E),
|
81
|
+
"Eritrea" => %i(C L),
|
82
|
+
"Estonia" => %i(C F),
|
83
|
+
"Ethiopia" => %i(C F G),
|
84
|
+
"Falkland Islands (Malvinas)" => %i(G),
|
85
|
+
"Faroe Islands" => %i(C E F K),
|
86
|
+
"Fiji" => %i(I),
|
87
|
+
"Finland" => %i(C F),
|
88
|
+
"France" => %i(C E),
|
89
|
+
"French Guiana" => %i(C E),
|
90
|
+
"French Polynesia" => %i(C E),
|
91
|
+
"Gabon" => %i(C E),
|
92
|
+
"Gambia" => %i(G),
|
93
|
+
"Gaza" => %i(C H),
|
94
|
+
"Georgia" => %i(C F),
|
95
|
+
"Germany" => %i(C F),
|
96
|
+
"Ghana" => %i(D G),
|
97
|
+
"Gibraltar" => %i(G),
|
98
|
+
"Great Britain" => %i(G),
|
99
|
+
"Greece" => %i(C F),
|
100
|
+
"Greenland" => %i(C E F K),
|
101
|
+
"Grenada" => %i(G),
|
102
|
+
"Guadeloupe" => %i(C E),
|
103
|
+
"Guam" => %i(A B),
|
104
|
+
"Guatemala" => %i(A B),
|
105
|
+
"Guernsey" => %i(C G),
|
106
|
+
"Guinea" => %i(C F),
|
107
|
+
"Guinea-Bissau" => %i(C E F),
|
108
|
+
"Guyana" => %i(A B D G),
|
109
|
+
"Haiti" => %i(A B),
|
110
|
+
"Honduras" => %i(A B),
|
111
|
+
"Hong Kong" => %i(G),
|
112
|
+
"Hungary" => %i(C F),
|
113
|
+
"Iceland" => %i(C F),
|
114
|
+
"India" => %i(C D M),
|
115
|
+
"Indonesia" => %i(C F),
|
116
|
+
"Iran" => %i(C F),
|
117
|
+
"Iraq" => %i(C D G),
|
118
|
+
"Ireland" => %i(G),
|
119
|
+
"Isle of Man" => %i(C G),
|
120
|
+
"Israel" => %i(C H),
|
121
|
+
"Italy" => %i(C F L),
|
122
|
+
"Jamaica" => %i(A B),
|
123
|
+
"Japan" => %i(A B),
|
124
|
+
"Jersey" => %i(C G),
|
125
|
+
"Jordan" => %i(C D F G J),
|
126
|
+
"Kazakhstan" => %i(C F),
|
127
|
+
"Kenya" => %i(G),
|
128
|
+
"Kiribati" => %i(I),
|
129
|
+
"Kosovo" => %i(C F),
|
130
|
+
"Kuwait" => %i(G),
|
131
|
+
"Kyrgyzstan" => %i(C F),
|
132
|
+
"Laos" => %i(A B C E F),
|
133
|
+
"Latvia" => %i(C F),
|
134
|
+
"Lebanon" => %i(C D G),
|
135
|
+
"Lesotho" => %i(M),
|
136
|
+
"Liberia" => %i(A B C F),
|
137
|
+
"Libya" => %i(C L),
|
138
|
+
"Liechtenstein" => %i(C J),
|
139
|
+
"Lithuania" => %i(C F),
|
140
|
+
"Luxembourg" => %i(C F),
|
141
|
+
"Macao" => %i(G),
|
142
|
+
"Madagascar" => %i(C E),
|
143
|
+
"Madeira" => %i(C F),
|
144
|
+
"Malawi" => %i(G),
|
145
|
+
"Malaysia" => %i(G),
|
146
|
+
"Maldives" => %i(C D G L),
|
147
|
+
"Mali" => %i(C E),
|
148
|
+
"Malta" => %i(G),
|
149
|
+
"Marshall Islands" => %i(A B),
|
150
|
+
"Martinique" => %i(C E),
|
151
|
+
"Mauritania" => %i(C E F),
|
152
|
+
"Mauritius" => %i(C G),
|
153
|
+
"Mayotte" => %i(C E),
|
154
|
+
"Mexico" => %i(A B),
|
155
|
+
"Micronesia" => %i(A B),
|
156
|
+
"Moldova" => %i(C F),
|
157
|
+
"Monaco" => %i(C E F),
|
158
|
+
"Mongolia" => %i(C F),
|
159
|
+
"Montenegro" => %i(C F),
|
160
|
+
"Montserrat" => %i(A B),
|
161
|
+
"Morocco" => %i(C E),
|
162
|
+
"Mozambique" => %i(C F M),
|
163
|
+
"Myanmar" => %i(A C D G I),
|
164
|
+
"Namibia" => %i(D M),
|
165
|
+
"Nauru" => %i(I),
|
166
|
+
"Nepal" => %i(C D M),
|
167
|
+
"Netherlands" => %i(C F),
|
168
|
+
"Netherlands Antilles" => %i(A B),
|
169
|
+
"New Caledonia" => %i(C E),
|
170
|
+
"New Zealand" => %i(I),
|
171
|
+
"Nicaragua" => %i(A B),
|
172
|
+
"Niger" => %i(C D E),
|
173
|
+
"Nigeria" => %i(D G),
|
174
|
+
"Niue" => %i(I),
|
175
|
+
"Norfolk Island" => %i(I),
|
176
|
+
"North Korea" => %i(C F),
|
177
|
+
"North Macedonia" => %i(C F),
|
178
|
+
"Northern Ireland" => %i(G),
|
179
|
+
"Northern Mariana Islands" => %i(A B),
|
180
|
+
"Norway" => %i(C F),
|
181
|
+
"Oman" => %i(G),
|
182
|
+
"Pakistan" => %i(C D),
|
183
|
+
"Palau" => %i(A B),
|
184
|
+
"Palestine" => %i(C H),
|
185
|
+
"Panama" => %i(A B),
|
186
|
+
"Papua New Guinea" => %i(I),
|
187
|
+
"Paraguay" => %i(A C),
|
188
|
+
"Peru" => %i(A B C),
|
189
|
+
"Philippines" => %i(A B C),
|
190
|
+
"Pitcairn Islands" => %i(I),
|
191
|
+
"Poland" => %i(C E),
|
192
|
+
"Portugal" => %i(C F),
|
193
|
+
"Puerto Rico" => %i(A B),
|
194
|
+
"Qatar" => %i(G),
|
195
|
+
"Reunion" => %i(C E),
|
196
|
+
"Romania" => %i(C F),
|
197
|
+
"Russia" => %i(C F),
|
198
|
+
"Rwanda" => %i(C E F G),
|
199
|
+
"Saba" => %i(A B),
|
200
|
+
"Saint Barthelemy" => %i(C E),
|
201
|
+
"Saint Helena" => %i(G),
|
202
|
+
"Saint Kitts and Nevis" => %i(D G),
|
203
|
+
"Saint Lucia" => %i(G),
|
204
|
+
"Saint Martin" => %i(C E),
|
205
|
+
"Saint Pierre and Miquelon" => %i(C E),
|
206
|
+
"Saint Vincent and the Grenadines" => %i(A B G),
|
207
|
+
"Samoa" => %i(I),
|
208
|
+
"San Marino" => %i(C F L),
|
209
|
+
"Sao Tome and Principe" => %i(C F),
|
210
|
+
"Saudi Arabia" => %i(G),
|
211
|
+
"Scottland" => %i(G),
|
212
|
+
"Senegal" => %i(C D E),
|
213
|
+
"Serbia" => %i(C F),
|
214
|
+
"Seychelles" => %i(G),
|
215
|
+
"Sierra Leone" => %i(D G),
|
216
|
+
"Singapore" => %i(G),
|
217
|
+
"Sint Eustatius" => %i(A B C F),
|
218
|
+
"Sint Maarten" => %i(A B),
|
219
|
+
"Slovakia" => %i(C E),
|
220
|
+
"Slovenia" => %i(C F),
|
221
|
+
"Solomon Islands" => %i(G I),
|
222
|
+
"Somalia" => %i(C G),
|
223
|
+
"South Africa" => %i(C M N),
|
224
|
+
"South Korea" => %i(C F),
|
225
|
+
"South Sudan" => %i(C D),
|
226
|
+
"Spain" => %i(C F),
|
227
|
+
"Sri Lanka" => %i(G),
|
228
|
+
"Sudan" => %i(C D),
|
229
|
+
"Suriname" => %i(A B C F),
|
230
|
+
"Svalbard and Jan Mayen" => %i(F),
|
231
|
+
"Swaziland" => %i(M),
|
232
|
+
"Sweden" => %i(C F),
|
233
|
+
"Switzerland" => %i(C J),
|
234
|
+
"Syria" => %i(C E L),
|
235
|
+
"Tahiti" => %i(C E),
|
236
|
+
"Taiwan" => %i(A B),
|
237
|
+
"Tajikistan" => %i(C F),
|
238
|
+
"Tanzania" => %i(D G),
|
239
|
+
"Thailand" => %i(A B C O),
|
240
|
+
"Togo" => %i(C E),
|
241
|
+
"Tokelau" => %i(I),
|
242
|
+
"Tonga" => %i(I),
|
243
|
+
"Trinidad and Tobago" => %i(A B),
|
244
|
+
"Tunisia" => %i(C E),
|
245
|
+
"Turkey" => %i(C F),
|
246
|
+
"Turkmenistan" => %i(C F),
|
247
|
+
"Turks and Caicos Islands" => %i(A B),
|
248
|
+
"Tuvalu" => %i(I),
|
249
|
+
"Uganda" => %i(G),
|
250
|
+
"Ukraine" => %i(C F),
|
251
|
+
"United Arab Emirates" => %i(G),
|
252
|
+
"United Kingdom" => %i(G),
|
253
|
+
"United States" => %i(A B),
|
254
|
+
"United States of America" => %i(A B),
|
255
|
+
"USA" => %i(A B),
|
256
|
+
"United States Virgin Islands" => %i(A B),
|
257
|
+
"Uruguay" => %i(C F L),
|
258
|
+
"Uzbekistan" => %i(C F),
|
259
|
+
"Vanuatu" => %i(I),
|
260
|
+
"Vatican City" => %i(C F L),
|
261
|
+
"Venezuela" => %i(A B),
|
262
|
+
"Vietnam" => %i(A B C),
|
263
|
+
"Wales" => %i(G),
|
264
|
+
"Wallis and Futuna" => %i(C E),
|
265
|
+
"West Bank" => %i(C H),
|
266
|
+
"Western Sahara" => %i(C E),
|
267
|
+
"Yemen" => %i(A D G),
|
268
|
+
"Zambia" => %i(C D G),
|
269
|
+
"Zimbabwe" => %i(D G)
|
270
|
+
}
|
271
|
+
|
272
|
+
# A hash with a socket type as the key and and array with plugs that fit that particular socket
|
273
|
+
SOCKETS_PLUGS = {
|
274
|
+
:A => %i(A),
|
275
|
+
:B => %i(A B),
|
276
|
+
:C => %i(C E F),
|
277
|
+
:D => %i(D),
|
278
|
+
:E => %i(C E),
|
279
|
+
:F => %i(C E F),
|
280
|
+
:G => %i(G),
|
281
|
+
:I => %i(I),
|
282
|
+
:J => %i(C J),
|
283
|
+
:K => %i(C E F K),
|
284
|
+
:L => %i(C L),
|
285
|
+
:M => %i(M),
|
286
|
+
:N => %i(C N),
|
287
|
+
:O => %i(C O)
|
288
|
+
}
|
289
|
+
|
290
|
+
# Gets the array of sockets for the country given as the parameter
|
291
|
+
def get_sockets(country)
|
292
|
+
COUNTRIES_SOCKETS[country]
|
293
|
+
end
|
294
|
+
|
295
|
+
# Gets the array of plugs that fit the socket given as the parameter
|
296
|
+
def get_plugs(socket)
|
297
|
+
SOCKETS_PLUGS[socket]
|
298
|
+
end
|
299
|
+
|
300
|
+
# Checks if the country given as the parameter is included in the hash COUNTRIES_SOCKETS and is therewith a valid country name
|
301
|
+
def validate_country_name(country)
|
302
|
+
COUNTRIES_SOCKETS.include?(country)
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'countries_sockets_plugs'
|
2
|
+
|
3
|
+
module SuckySocket
|
4
|
+
class Country
|
5
|
+
|
6
|
+
include CountriesSocketsPlugs
|
7
|
+
|
8
|
+
attr_reader :name, :sockets
|
9
|
+
|
10
|
+
# Use USA as default start_country when no country was entered by the user
|
11
|
+
def initialize(name = "USA")
|
12
|
+
if validate_country_name(name)
|
13
|
+
@name = name
|
14
|
+
@sockets = get_sockets("#{@name}")
|
15
|
+
else
|
16
|
+
puts "Country #{name} was not found in the database."
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Checks whether an adapter is needed by comparing whether the plugs of the start country match the plugs that work with every particular socket of the destination country
|
22
|
+
def needs_adapter_for?(dest_country)
|
23
|
+
|
24
|
+
dest_plugs = []
|
25
|
+
dest_country.sockets.each do |s|
|
26
|
+
dest_plugs << get_plugs(s)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
problem_plugs = []
|
31
|
+
dest_plugs.each do |dp|
|
32
|
+
problem_plugs << (sockets - dp)
|
33
|
+
end
|
34
|
+
|
35
|
+
if problem_plugs.flatten.size == 0
|
36
|
+
puts "\nNo adapter needed when travelling from #{name} to #{dest_country.name}."
|
37
|
+
return false
|
38
|
+
elsif problem_plugs.select { |pp| pp.sort != sockets }.size == 0
|
39
|
+
puts "\nAdapter is definetely needed when travelling from #{name} to #{dest_country.name} because the plugs in #{name} don't fit any of the sockets in #{dest_country.name}."
|
40
|
+
return true
|
41
|
+
else
|
42
|
+
puts "\nAdapter is needed when travelling from #{name} to #{dest_country.name} because:"
|
43
|
+
problem_plugs.each_with_index do |plug, ind|
|
44
|
+
if plug.size == 1
|
45
|
+
puts " - The plug type #{plug.join(', ')} does not fit into socket type #{dest_country.sockets[ind]}"
|
46
|
+
elsif plug.size > 1
|
47
|
+
puts " - The plug types #{plug.join(', ')} don't fit into socket type #{dest_country.sockets[ind]}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
expectations.syntax = [:should, :expect]
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
mocks.syntax = [:should, :expect]
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
=begin
|
52
|
+
# This allows you to limit a spec run to individual examples or groups
|
53
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
54
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
55
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
56
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
57
|
+
config.filter_run_when_matching :focus
|
58
|
+
|
59
|
+
# Allows RSpec to persist some state between runs in order to support
|
60
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
61
|
+
# you configure your source control system to ignore this file.
|
62
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
63
|
+
|
64
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
65
|
+
# recommended. For more details, see:
|
66
|
+
# https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
|
67
|
+
config.disable_monkey_patching!
|
68
|
+
|
69
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
70
|
+
# be too noisy due to issues in dependencies.
|
71
|
+
config.warnings = true
|
72
|
+
|
73
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
74
|
+
# file, and it's useful to allow more verbose output when running an
|
75
|
+
# individual spec file.
|
76
|
+
if config.files_to_run.one?
|
77
|
+
# Use the documentation formatter for detailed output,
|
78
|
+
# unless a formatter has already been configured
|
79
|
+
# (e.g. via a command-line flag).
|
80
|
+
config.default_formatter = "doc"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Print the 10 slowest examples and example groups at the
|
84
|
+
# end of the spec run, to help surface which specs are running
|
85
|
+
# particularly slow.
|
86
|
+
config.profile_examples = 10
|
87
|
+
|
88
|
+
# Run specs in random order to surface order dependencies. If you find an
|
89
|
+
# order dependency and want to debug it, you can fix the order by providing
|
90
|
+
# the seed, which is printed after each run.
|
91
|
+
# --seed 1234
|
92
|
+
config.order = :random
|
93
|
+
|
94
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
95
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
96
|
+
# test failures related to randomization by passing the same `--seed` value
|
97
|
+
# as the one that triggered the failure.
|
98
|
+
Kernel.srand config.seed
|
99
|
+
=end
|
100
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sucky_socket/countries_sockets_plugs'
|
2
|
+
|
3
|
+
module SuckySocket
|
4
|
+
describe "Countries_Sockets contant" do
|
5
|
+
|
6
|
+
it "checks if each country has sockets" do
|
7
|
+
CountriesSocketsPlugs::COUNTRIES_SOCKETS.each do |c|
|
8
|
+
expect(c[1]).to_not be_empty
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "checks if each socket has plugs" do
|
13
|
+
CountriesSocketsPlugs::SOCKETS_PLUGS.each do |s|
|
14
|
+
expect(s[1]).to_not be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'sucky_socket/country'
|
2
|
+
require 'sucky_socket/countries_sockets_plugs'
|
3
|
+
|
4
|
+
module SuckySocket
|
5
|
+
describe Country do
|
6
|
+
|
7
|
+
include CountriesSocketsPlugs
|
8
|
+
|
9
|
+
context "with USA as default" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@start = Country.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it "checks that the name is USA" do
|
16
|
+
expect(@start.name).to eq "USA"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "expects that the sockets are [:A, :B]" do
|
20
|
+
expect(@start.sockets).to eq [:A, :B]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "checks that the plugs are [[:A], [:A, :B]]" do
|
24
|
+
plugs = []
|
25
|
+
@start.sockets.each do |socket|
|
26
|
+
plugs << get_plugs(socket)
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(plugs).to eq [[:A], [:A, :B]]
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with a valid country name" do
|
35
|
+
|
36
|
+
before do
|
37
|
+
@start_country = Country.new("Germany")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "checks that the country name is valid" do
|
41
|
+
expect(@start_country.name).to eq "Germany"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "checks that the input country has valid sockets" do
|
45
|
+
expect(@start_country.sockets).to eq [:C, :F]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "checks that an adapter is not needed" do
|
49
|
+
dest_country = Country.new("Sweden")
|
50
|
+
expect(@start_country.needs_adapter_for?(dest_country)).to be false
|
51
|
+
expect do
|
52
|
+
@start_country.needs_adapter_for?(dest_country)
|
53
|
+
end.to output("\nNo adapter needed when travelling from Germany to Sweden.\n").to_stdout
|
54
|
+
end
|
55
|
+
|
56
|
+
it "checks that an adapter is definetely needed" do
|
57
|
+
dest_country = Country.new("Bermuda")
|
58
|
+
expect(@start_country.needs_adapter_for?(dest_country)).to be true
|
59
|
+
expect do
|
60
|
+
@start_country.needs_adapter_for?(dest_country)
|
61
|
+
end.to output("\nAdapter is definetely needed when travelling from Germany to Bermuda because the plugs in Germany don't fit any of the sockets in Bermuda.\n").to_stdout
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
it "checks that an adapter is possibly needed" do
|
66
|
+
dest_country = Country.new("Thailand")
|
67
|
+
expect(@start_country.needs_adapter_for?(dest_country)).to be true
|
68
|
+
expect do
|
69
|
+
@start_country.needs_adapter_for?(dest_country)
|
70
|
+
end.to output("\nAdapter is needed when travelling from Germany to Thailand because:\n - The plug types C, F don't fit into socket type A\n - The plug types C, F don't fit into socket type B\n - The plug type F does not fit into socket type O\n").to_stdout
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with an unvalid country name" do
|
75
|
+
|
76
|
+
it "checks that an unvalid name does not get validated" do
|
77
|
+
expect do
|
78
|
+
country = Country.new("Dkldjee")
|
79
|
+
end.to output("Country Dkldjee was not found in the database.").to_stdout
|
80
|
+
|
81
|
+
country = Country.new("Dkldjee")
|
82
|
+
expect(country).to be true
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: suckysockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BluePeony
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.8.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.8'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.0
|
33
|
+
description: "The suckysockets gem provides the user with the opportunity to check
|
34
|
+
whether a power adapter is needed when travelling from one country to another.\n\n1.
|
35
|
+
How to install the gem\ngem install suckysockets\n\n2. How to use it\nTo run the
|
36
|
+
program just type 'suckysockets' in the command line. \n\nYou will be asked in which
|
37
|
+
country you currently live. Please type the country name and press 'enter'. \nNext
|
38
|
+
you need to enter your destination country and press 'enter' again.\nThen you receive
|
39
|
+
the result telling you whether or nor you need an adapter travelling from you current
|
40
|
+
country to the destination country. \n\nThree outcomes are possible:\n - an adapter
|
41
|
+
is not needed. That is the case when all plugs common in your country of living
|
42
|
+
fit all of the sockets in your destination country.\n - an adapter is definetely
|
43
|
+
needed. That is the case when none of the plugs in your home country fit any of
|
44
|
+
the sockets in your destination country.\n - an adapter is needed in certain cases:
|
45
|
+
when some of your home country plugs fit some of the sockets, but some plugs don't.
|
46
|
+
In that case you will get a detailed response telling you for which particular cases
|
47
|
+
an adapter is needed. "
|
48
|
+
email: blue.peony2314@gmail.com
|
49
|
+
executables:
|
50
|
+
- suckysockets
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- README
|
56
|
+
- bin/suckysockets
|
57
|
+
- lib/sucky_socket/countries_sockets_plugs.rb
|
58
|
+
- lib/sucky_socket/country.rb
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
- spec/sucky_socket/countries_sockets_plugs_spec.rb
|
61
|
+
- spec/sucky_socket/country_spec.rb
|
62
|
+
homepage: https://github.com/BluePeony/suckysockets
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.9'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.4.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Command line tool to check whether a power adapter is needed when travelling
|
85
|
+
from country A to country B
|
86
|
+
test_files:
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/sucky_socket/countries_sockets_plugs_spec.rb
|
89
|
+
- spec/sucky_socket/country_spec.rb
|