turkish_cities 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d0cd05d34a416272e2b661c675e262f27737396cf43cad8a73ecc87d21c19fcb
4
+ data.tar.gz: ebfffaf7f5e7a1790b6300ea1f377c35aac9b1792d571315379ecd954ccaff0e
5
+ SHA512:
6
+ metadata.gz: 66047b377afdd925f20c54e8a17e40b3985b4919f2010e8dd82f59bf59a22a1afb5612b6487085503f21ebfb18cd11692c9ca5e89563e65a1df4c93e81e8af12
7
+ data.tar.gz: 3c46b9903d71b2325219f8fb7f3339df600e5a0a7d1d8abd8295ee70d031760b489b1353bcaaddef3ae4705a8523589c5520bb858f12c461cefefcd4be7657c7
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'turkish_cities/city'
4
+
5
+ class TurkishCities
6
+ def self.find_name_by_plate_number(plate_number)
7
+ City.new.find_by_id(plate_number)
8
+ end
9
+
10
+ def self.find_plate_number_by_name(city_name)
11
+ City.new.find_by_name(city_name)
12
+ end
13
+
14
+ def self.list_cities(options = {})
15
+ City.new.list_cities(options)
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'i18n'
4
+ require 'turkish_cities/data/city_list'
5
+
6
+ class City
7
+ I18n.enforce_available_locales = false
8
+
9
+ def find_by_id(plate_number)
10
+ CITY_LIST[plate_number][:name]
11
+ end
12
+
13
+ def find_by_name(city_name)
14
+ CITY_LIST.select do |key, hash|
15
+ return key if convert_chars(hash[:name].downcase) == convert_chars(city_name.downcase)
16
+ end
17
+ end
18
+
19
+ def list_cities(options)
20
+ city_list = ['-- select city --']
21
+ CITY_LIST.each_value.select do |attributes|
22
+ if options[:metropolitan_municipality]
23
+ city_list.push(attributes[:name]) unless attributes[:metropolitan_municipality_since].nil?
24
+ else
25
+ city_list.push(attributes[:name])
26
+ end
27
+ end
28
+ options[:alphabetically_sorted] ? sort_cities(city_list) : city_list
29
+ end
30
+
31
+ private
32
+
33
+ def convert_chars(string)
34
+ I18n.transliterate(string)
35
+ end
36
+
37
+ def sort_cities(city_list)
38
+ turkish_alphabet = ' -abcçdefgğhıijklmnoöprsştuüvyz'
39
+ city_list.sort_by do |city|
40
+ city.downcase(:turkic).chars.map { |char| turkish_alphabet.index(char) }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ CITY_LIST = {
4
+ 1 => { name: 'Adana',
5
+ phone_code: 322,
6
+ metropolitan_municipality_since: 1986 },
7
+ 2 => { name: 'Adıyaman',
8
+ phone_code: 416,
9
+ metropolitan_municipality_since: nil },
10
+ 3 => { name: 'Afyon',
11
+ phone_code: 272,
12
+ metropolitan_municipality_since: nil },
13
+ 4 => { name: 'Ağrı',
14
+ phone_code: 472,
15
+ metropolitan_municipality_since: nil },
16
+ 5 => { name: 'Amasya',
17
+ phone_code: 358,
18
+ metropolitan_municipality_since: nil },
19
+ 6 => { name: 'Ankara',
20
+ phone_code: 312,
21
+ metropolitan_municipality_since: 1984 },
22
+ 7 => { name: 'Antalya',
23
+ phone_code: 242,
24
+ metropolitan_municipality_since: 1993 },
25
+ 8 => { name: 'Artvin',
26
+ phone_code: 466,
27
+ metropolitan_municipality_since: nil },
28
+ 9 => { name: 'Aydın',
29
+ phone_code: 256,
30
+ metropolitan_municipality_since: 2012 },
31
+ 10 => { name: 'Balıkesir',
32
+ phone_code: 266,
33
+ metropolitan_municipality_since: 2012 },
34
+ 11 => { name: 'Bilecik',
35
+ phone_code: 228,
36
+ metropolitan_municipality_since: nil },
37
+ 12 => { name: 'Bingöl',
38
+ phone_code: 426,
39
+ metropolitan_municipality_since: nil },
40
+ 13 => { name: 'Bitlis',
41
+ phone_code: 434,
42
+ metropolitan_municipality_since: nil },
43
+ 14 => { name: 'Bolu',
44
+ phone_code: 374,
45
+ metropolitan_municipality_since: nil },
46
+ 15 => { name: 'Burdur',
47
+ phone_code: 248,
48
+ metropolitan_municipality_since: nil },
49
+ 16 => { name: 'Bursa',
50
+ phone_code: 224,
51
+ metropolitan_municipality_since: 1987 },
52
+ 17 => { name: 'Çanakkale',
53
+ phone_code: 286,
54
+ metropolitan_municipality_since: nil },
55
+ 18 => { name: 'Çankırı',
56
+ phone_code: 376,
57
+ metropolitan_municipality_since: nil },
58
+ 19 => { name: 'Çorum',
59
+ phone_code: 364,
60
+ metropolitan_municipality_since: nil },
61
+ 20 => { name: 'Denizli',
62
+ phone_code: 258,
63
+ metropolitan_municipality_since: 2012 },
64
+ 21 => { name: 'Diyarbakır',
65
+ phone_code: 412,
66
+ metropolitan_municipality_since: 1993 },
67
+ 22 => { name: 'Edirne',
68
+ phone_code: 284,
69
+ metropolitan_municipality_since: nil },
70
+ 23 => { name: 'Elazığ',
71
+ phone_code: 424,
72
+ metropolitan_municipality_since: nil },
73
+ 24 => { name: 'Erzincan',
74
+ phone_code: 446,
75
+ metropolitan_municipality_since: nil },
76
+ 25 => { name: 'Erzurum',
77
+ phone_code: 442,
78
+ metropolitan_municipality_since: 1993 },
79
+ 26 => { name: 'Eskişehir',
80
+ phone_code: 222,
81
+ metropolitan_municipality_since: 1993 },
82
+ 27 => { name: 'Gaziantep',
83
+ phone_code: 342,
84
+ metropolitan_municipality_since: 1987 },
85
+ 28 => { name: 'Giresun',
86
+ phone_code: 454,
87
+ metropolitan_municipality_since: nil },
88
+ 29 => { name: 'Gümüşhane',
89
+ phone_code: 456,
90
+ metropolitan_municipality_since: nil },
91
+ 30 => { name: 'Hakkari',
92
+ phone_code: 438,
93
+ metropolitan_municipality_since: nil },
94
+ 31 => { name: 'Hatay',
95
+ phone_code: 326,
96
+ metropolitan_municipality_since: 2012 },
97
+ 32 => { name: 'Isparta',
98
+ phone_code: 246,
99
+ metropolitan_municipality_since: nil },
100
+ 33 => { name: 'Mersin',
101
+ phone_code: 324,
102
+ metropolitan_municipality_since: 1993 },
103
+ 34 => { name: 'İstanbul',
104
+ phone_code: [212, 216],
105
+ metropolitan_municipality_since: 1984 },
106
+ 35 => { name: 'İzmir',
107
+ phone_code: 232,
108
+ metropolitan_municipality_since: 1984 },
109
+ 36 => { name: 'Kars',
110
+ phone_code: 474,
111
+ metropolitan_municipality_since: nil },
112
+ 37 => { name: 'Kastamonu',
113
+ phone_code: 366,
114
+ metropolitan_municipality_since: nil },
115
+ 38 => { name: 'Kayseri',
116
+ phone_code: 352,
117
+ metropolitan_municipality_since: 1988 },
118
+ 39 => { name: 'Kırklareli',
119
+ phone_code: 288,
120
+ metropolitan_municipality_since: nil },
121
+ 40 => { name: 'Kırşehir',
122
+ phone_code: 386,
123
+ metropolitan_municipality_since: nil },
124
+ 41 => { name: 'Kocaeli',
125
+ phone_code: 262,
126
+ metropolitan_municipality_since: 1993 },
127
+ 42 => { name: 'Konya',
128
+ phone_code: 332,
129
+ metropolitan_municipality_since: 1987 },
130
+ 43 => { name: 'Kütahya',
131
+ phone_code: 274,
132
+ metropolitan_municipality_since: nil },
133
+ 44 => { name: 'Malatya',
134
+ phone_code: 422,
135
+ metropolitan_municipality_since: 2012 },
136
+ 45 => { name: 'Manisa',
137
+ phone_code: 236,
138
+ metropolitan_municipality_since: 2012 },
139
+ 46 => { name: 'Kahramanmaraş',
140
+ phone_code: 344,
141
+ metropolitan_municipality_since: 2012 },
142
+ 47 => { name: 'Mardin',
143
+ phone_code: 482,
144
+ metropolitan_municipality_since: 2012 },
145
+ 48 => { name: 'Muğla',
146
+ phone_code: 252,
147
+ metropolitan_municipality_since: 2012 },
148
+ 49 => { name: 'Muş',
149
+ phone_code: 436,
150
+ metropolitan_municipality_since: nil },
151
+ 50 => { name: 'Nevşehir',
152
+ phone_code: 384,
153
+ metropolitan_municipality_since: nil },
154
+ 51 => { name: 'Niğde',
155
+ phone_code: 388,
156
+ metropolitan_municipality_since: nil },
157
+ 52 => { name: 'Ordu',
158
+ phone_code: 452,
159
+ metropolitan_municipality_since: 2012 },
160
+ 53 => { name: 'Rize',
161
+ phone_code: 464,
162
+ metropolitan_municipality_since: nil },
163
+ 54 => { name: 'Sakarya',
164
+ phone_code: 264,
165
+ metropolitan_municipality_since: 2000 },
166
+ 55 => { name: 'Samsun',
167
+ phone_code: 362,
168
+ metropolitan_municipality_since: 1993 },
169
+ 56 => { name: 'Siirt',
170
+ phone_code: 484,
171
+ metropolitan_municipality_since: nil },
172
+ 57 => { name: 'Sinop',
173
+ phone_code: 368,
174
+ metropolitan_municipality_since: nil },
175
+ 58 => { name: 'Sivas',
176
+ phone_code: 346,
177
+ metropolitan_municipality_since: nil },
178
+ 59 => { name: 'Tekirdağ',
179
+ phone_code: 282,
180
+ metropolitan_municipality_since: 2012 },
181
+ 60 => { name: 'Tokat',
182
+ phone_code: 356,
183
+ metropolitan_municipality_since: nil },
184
+ 61 => { name: 'Trabzon',
185
+ phone_code: 462,
186
+ metropolitan_municipality_since: 2012 },
187
+ 62 => { name: 'Tunceli',
188
+ phone_code: 428,
189
+ metropolitan_municipality_since: nil },
190
+ 63 => { name: 'Şanlıurfa',
191
+ phone_code: 414,
192
+ metropolitan_municipality_since: 2012 },
193
+ 64 => { name: 'Uşak',
194
+ phone_code: 276,
195
+ metropolitan_municipality_since: nil },
196
+ 65 => { name: 'Van',
197
+ phone_code: 432,
198
+ metropolitan_municipality_since: 2012 },
199
+ 66 => { name: 'Yozgat',
200
+ phone_code: 354,
201
+ metropolitan_municipality_since: nil },
202
+ 67 => { name: 'Zonguldak',
203
+ phone_code: 372,
204
+ metropolitan_municipality_since: nil },
205
+ 68 => { name: 'Aksaray',
206
+ phone_code: 382,
207
+ metropolitan_municipality_since: nil },
208
+ 69 => { name: 'Bayburt',
209
+ phone_code: 458,
210
+ metropolitan_municipality_since: nil },
211
+ 70 => { name: 'Karaman',
212
+ phone_code: 338,
213
+ metropolitan_municipality_since: nil },
214
+ 71 => { name: 'Kırıkkale',
215
+ phone_code: 318,
216
+ metropolitan_municipality_since: nil },
217
+ 72 => { name: 'Batman',
218
+ phone_code: 488,
219
+ metropolitan_municipality_since: nil },
220
+ 73 => { name: 'Şırnak',
221
+ phone_code: 486,
222
+ metropolitan_municipality_since: nil },
223
+ 74 => { name: 'Bartın',
224
+ phone_code: 378,
225
+ metropolitan_municipality_since: nil },
226
+ 75 => { name: 'Ardahan',
227
+ phone_code: 478,
228
+ metropolitan_municipality_since: nil },
229
+ 76 => { name: 'Iğdır',
230
+ phone_code: 476,
231
+ metropolitan_municipality_since: nil },
232
+ 77 => { name: 'Yalova',
233
+ phone_code: 226,
234
+ metropolitan_municipality_since: nil },
235
+ 78 => { name: 'Karabük',
236
+ phone_code: 370,
237
+ metropolitan_municipality_since: nil },
238
+ 79 => { name: 'Kilis',
239
+ phone_code: 348,
240
+ metropolitan_municipality_since: nil },
241
+ 80 => { name: 'Osmaniye',
242
+ phone_code: 328,
243
+ metropolitan_municipality_since: nil },
244
+ 81 => { name: 'Düzce',
245
+ phone_code: 380,
246
+ metropolitan_municipality_since: nil }
247
+ }.freeze
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turkish_cities
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Semih Arslanoglu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple ruby gem for listing turkish cities
14
+ email: arslanoglusemih93@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/turkish_cities.rb
20
+ - lib/turkish_cities/city.rb
21
+ - lib/turkish_cities/data/city_list.rb
22
+ homepage: https://rubygems.org/gems/turkish_cities
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.1.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Discover The Potential
45
+ test_files: []