turkish_cities 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +34 -0
  3. data/.github/dependabot.yml +20 -0
  4. data/.github/workflows/ruby.yml +39 -0
  5. data/.hound.yml +1 -1
  6. data/.rubocop.yml +3 -1
  7. data/CHANGELOG.md +22 -0
  8. data/Gemfile.lock +43 -51
  9. data/README.md +237 -33
  10. data/Rakefile +11 -0
  11. data/config/locales/en.yml +19 -0
  12. data/config/locales/tr.yml +19 -0
  13. data/lib/turkish_cities/city.rb +1 -3
  14. data/lib/turkish_cities/data/cities.yaml +81 -0
  15. data/lib/turkish_cities/data/districts/adana.yaml +1 -1
  16. data/lib/turkish_cities/data/districts/adiyaman.yaml +184 -176
  17. data/lib/turkish_cities/data/districts/afyon.yaml +295 -189
  18. data/lib/turkish_cities/data/districts/agri.yaml +28 -28
  19. data/lib/turkish_cities/data/districts/aksaray.yaml +90 -61
  20. data/lib/turkish_cities/data/districts/amasya.yaml +17 -6
  21. data/lib/turkish_cities/data/districts/ankara.yaml +22 -22
  22. data/lib/turkish_cities/data/districts/antalya.yaml +3 -3
  23. data/lib/turkish_cities/data/districts/ardahan.yaml +10 -7
  24. data/lib/turkish_cities/data/districts/artvin.yaml +0 -60
  25. data/lib/turkish_cities/data/districts/bartin.yaml +23 -19
  26. data/lib/turkish_cities/data/districts/batman.yaml +45 -28
  27. data/lib/turkish_cities/data/districts/bayburt.yaml +12 -6
  28. data/lib/turkish_cities/data/districts/bilecik.yaml +18 -14
  29. data/lib/turkish_cities/data/districts/bingol.yaml +29 -35
  30. data/lib/turkish_cities/data/districts/bitlis.yaml +56 -43
  31. data/lib/turkish_cities/data/districts/bolu.yaml +34 -58
  32. data/lib/turkish_cities/data/districts/burdur.yaml +22 -16
  33. data/lib/turkish_cities/data/districts/bursa.yaml +3 -2
  34. data/lib/turkish_cities/data/districts/canakkale.yaml +46 -47
  35. data/lib/turkish_cities/data/districts/cankiri.yaml +23 -18
  36. data/lib/turkish_cities/data/districts/corum.yaml +25 -15
  37. data/lib/turkish_cities/data/districts/denizli.yaml +1 -1
  38. data/lib/turkish_cities/data/districts/diyarbakir.yaml +6 -6
  39. data/lib/turkish_cities/data/districts/duzce.yaml +83 -74
  40. data/lib/turkish_cities/data/districts/edirne.yaml +37 -23
  41. data/lib/turkish_cities/data/districts/elazig.yaml +74 -54
  42. data/lib/turkish_cities/data/districts/erzincan.yaml +47 -38
  43. data/lib/turkish_cities/data/districts/erzurum.yaml +1 -1
  44. data/lib/turkish_cities/data/districts/giresun.yaml +125 -57
  45. data/lib/turkish_cities/data/districts/gumushane.yaml +61 -81
  46. data/lib/turkish_cities/data/districts/hakkari.yaml +22 -15
  47. data/lib/turkish_cities/data/districts/hatay.yaml +1 -1
  48. data/lib/turkish_cities/data/districts/igdir.yaml +20 -11
  49. data/lib/turkish_cities/data/districts/isparta.yaml +67 -40
  50. data/lib/turkish_cities/data/districts/istanbul.yaml +12 -12
  51. data/lib/turkish_cities/data/districts/izmir.yaml +12 -12
  52. data/lib/turkish_cities/data/districts/kahramanmaras.yaml +3 -2
  53. data/lib/turkish_cities/data/districts/karabuk.yaml +15 -28
  54. data/lib/turkish_cities/data/districts/karaman.yaml +36 -31
  55. data/lib/turkish_cities/data/districts/kars.yaml +5 -4
  56. data/lib/turkish_cities/data/districts/kastamonu.yaml +3 -29
  57. data/lib/turkish_cities/data/districts/kayseri.yaml +8 -8
  58. data/lib/turkish_cities/data/districts/kilis.yaml +3 -2
  59. data/lib/turkish_cities/data/districts/kirikkale.yaml +17 -13
  60. data/lib/turkish_cities/data/districts/kirklareli.yaml +63 -45
  61. data/lib/turkish_cities/data/districts/kirsehir.yaml +25 -16
  62. data/lib/turkish_cities/data/districts/kocaeli.yaml +1 -1
  63. data/lib/turkish_cities/data/districts/konya.yaml +7 -8
  64. data/lib/turkish_cities/data/districts/kutahya.yaml +104 -72
  65. data/lib/turkish_cities/data/districts/malatya.yaml +1 -1
  66. data/lib/turkish_cities/data/districts/manisa.yaml +2 -2
  67. data/lib/turkish_cities/data/districts/mersin.yaml +4 -4
  68. data/lib/turkish_cities/data/districts/mus.yaml +118 -74
  69. data/lib/turkish_cities/data/districts/nevsehir.yaml +51 -43
  70. data/lib/turkish_cities/data/districts/nigde.yaml +135 -76
  71. data/lib/turkish_cities/data/districts/ordu.yaml +3 -3
  72. data/lib/turkish_cities/data/districts/osmaniye.yaml +53 -32
  73. data/lib/turkish_cities/data/districts/rize.yaml +68 -46
  74. data/lib/turkish_cities/data/districts/sakarya.yaml +2 -2
  75. data/lib/turkish_cities/data/districts/samsun.yaml +3 -3
  76. data/lib/turkish_cities/data/districts/sanliurfa.yaml +7 -7
  77. data/lib/turkish_cities/data/districts/siirt.yaml +27 -13
  78. data/lib/turkish_cities/data/districts/sinop.yaml +1 -5
  79. data/lib/turkish_cities/data/districts/sirnak.yaml +78 -40
  80. data/lib/turkish_cities/data/districts/sivas.yaml +49 -52
  81. data/lib/turkish_cities/data/districts/tekirdag.yaml +7 -2
  82. data/lib/turkish_cities/data/districts/tokat.yaml +201 -138
  83. data/lib/turkish_cities/data/districts/trabzon.yaml +1 -0
  84. data/lib/turkish_cities/data/districts/tunceli.yaml +13 -9
  85. data/lib/turkish_cities/data/districts/usak.yaml +40 -24
  86. data/lib/turkish_cities/data/districts/van.yaml +6 -4
  87. data/lib/turkish_cities/data/districts/yalova.yaml +45 -21
  88. data/lib/turkish_cities/data/districts/yozgat.yaml +147 -80
  89. data/lib/turkish_cities/data/districts/zonguldak.yaml +127 -90
  90. data/lib/turkish_cities/data/neighborhoods_parser.rb +4 -4
  91. data/lib/turkish_cities/distance.rb +7 -4
  92. data/lib/turkish_cities/helpers/decomposer_helper.rb +21 -7
  93. data/lib/turkish_cities/population.rb +66 -0
  94. data/lib/turkish_cities/version.rb +1 -1
  95. data/lib/turkish_cities.rb +23 -2
  96. data/turkish_cities.gemspec +4 -4
  97. metadata +34 -14
  98. data/.travis.yml +0 -21
data/README.md CHANGED
@@ -3,10 +3,12 @@
3
3
  <p align="center">
4
4
  <a href="https://rubygems.org/gems/turkish_cities">
5
5
  <img src="https://badge.fury.io/rb/turkish_cities.svg" alt="GemVersion"/></a>
6
- <a href="https://travis-ci.org/sarslanoglu/turkish_cities">
7
- <img src="https://travis-ci.org/sarslanoglu/turkish_cities.svg?branch=master" alt="BuildStatus"/></a>
8
- <a href="https://coveralls.io/github/sarslanoglu/turkish_cities?branch=master">
9
- <img src="https://coveralls.io/repos/github/sarslanoglu/turkish_cities/badge.svg?branch=master" alt="CoverageStatus"/></a>
6
+ <a href="https://app.circleci.com/pipelines/github/sarslanoglu/turkish_cities">
7
+ <img src="https://circleci.com/gh/sarslanoglu/turkish_cities.svg?style=shield" alt="BuildStatus"/></a>
8
+ <a href="https://codecov.io/gh/sarslanoglu/turkish_cities">
9
+ <img src="https://codecov.io/gh/sarslanoglu/turkish_cities/branch/master/graph/badge.svg?token=1SU7ZFI8ZJ"/></a>
10
+ <a href="https://rubygems.org/gems/turkish_cities">
11
+ <img src="https://img.shields.io/gem/dt/turkish_cities.svg" alt="DownloadCount"/></a>
10
12
  <a href="https://codeclimate.com/github/sarslanoglu/turkish_cities/maintainability">
11
13
  <img src="https://api.codeclimate.com/v1/badges/c1dbe0cef353b152956e/maintainability" alt="Maintainability"/></a>
12
14
  <a href="https://houndci.com">
@@ -18,30 +20,62 @@
18
20
  **Turkish Cities** is a Ruby gem which makes listing and finding Turkish cities easy. Search can be via name, post code, plate number, district name etc. Also calculate your travel distance and travel time between cities via distance methods.
19
21
  https://rubygems.org/gems/turkish_cities
20
22
 
23
+
21
24
  ## Table of Contents
22
- * [Installation](#installation)
23
- * [Documentation](#documentation)
24
- * [Finding city name by plate number](#finding-city-name-by-plate-number)
25
- * [Finding city name by phone code](#finding-city-name-by-phone-code)
26
- * [Finding plate number by city name](#finding-plate-number-by-city-name)
27
- * [Finding phone code by city name](#finding-phone-code-by-city-name)
28
- * [Listing all cities](#listing-all-cities)
29
- * [Listing all cities with only name](#listing-all-cities-with-only-name)
30
- * [Listing all cities with other parameters](#listing-all-cities-with-other-parameters)
31
- * [Listing all districts of given city](#listing-all-districts-of-given-city)
32
- * [Listing all subdistricts of given city and district](#listing-all-subdistricts-of-given-city-and-district)
33
- * [Listing all neighborhoods of given city and district](#listing-all-neighborhoods-of-given-city-and-district)
34
- * [With subdistrict info](#with-subdistrict-info)
35
- * [Without subdistrict info](#without-subdistrict-info)
36
- * [Finding city, district and subdistrict name by postcode](#finding-city-district-and-subdistrict-name-by-postcode)
37
- * [Finding travel distance and time estimation between two cities](#finding-travel-distance-and-time-estimation-between-two-cities)
38
- * [By land](#by-land)
39
- * [By air](#by-air)
40
- * [Data sources](#data-sources)
41
- * [Compatibility](#compatibility)
42
- * [Contributing](#contributing)
43
- * [Changelog](#changelog)
44
- * [Copyright](#copyright)
25
+ <details>
26
+ <summary>Table of Contents</summary>
27
+ <ul>
28
+ <li><a href="#installation">Installation</a></li>
29
+ <li><a href="#localization">Localization</a></li>
30
+ <li>
31
+ <a href="#documentation">Documentation</a>
32
+ <ul>
33
+ <li><a href="#finding-city-name-by-plate-number">Finding city name by plate number</a></li>
34
+ <li><a href="#finding-city-name-by-phone-code">Finding city name by phone code</a></li>
35
+ <li><a href="#finding-plate-number-by-city-name">Finding plate number by city name</a></li>
36
+ <li><a href="#finding-phone-code-by-city-name">Finding phone code by city name</a></li>
37
+ <li>
38
+ <a href="#listing-all-cities">Listing all cities</a>
39
+ <ul>
40
+ <li><a href="#listing-all-cities-with-only-name">Listing all cities with only name</a></li>
41
+ <li><a href="#listing-all-cities-with-other-parameters">Listing all cities with other parameters</a></li>
42
+ </ul>
43
+ </li>
44
+ <li><a href="#listing-all-districts-of-given-city">Listing all districts of given city</a></li>
45
+ <li><a href="#listing-all-subdistricts-of-given-city-and-district">Listing all subdistricts of given city and district</a></li>
46
+ <li>
47
+ <a href="#listing-all-neighborhoods-of-given-city-and-district">Listing all neighborhoods of given city and district</a>
48
+ <ul>
49
+ <li><a href="#with-subdistrict-info">With subdistrict info</a></li>
50
+ <li><a href="#without-subdistrict-info">Without subdistrict info</a></li>
51
+ </ul>
52
+ </li>
53
+ <li><a href="#finding-city-district-and-subdistrict-name-by-postcode">Finding city, district and subdistrict name by postcode</a></li>
54
+ <li>
55
+ <a href="#finding-city-name-with-population-data">Finding city name with population data</a>
56
+ <ul>
57
+ <li><a href="#exact-search">Exact search</a></li>
58
+ <li><a href="#below-given">Below given</a></li>
59
+ <li><a href="#above-given">Above given</a></li>
60
+ <li><a href="#between-search">Between search</a></li>
61
+ </ul>
62
+ </li>
63
+ <li>
64
+ <a href="#finding-travel-distance-and-time-estimation-between-two-cities">Finding travel distance and time estimation between two cities</a>
65
+ <ul>
66
+ <li><a href="#by-land">By land</a></li>
67
+ <li><a href="#by-air">By air</a></li>
68
+ </ul>
69
+ </li>
70
+ </ul>
71
+ </li>
72
+ <li><a href="#data-sources">Data sources</a></li>
73
+ <li><a href="#compatibility">Compatibility</a></li>
74
+ <li><a href="#contributing">Contributing</a></li>
75
+ <li><a href="#changelog">Changelog</a></li>
76
+ <li><a href="#copyright">Copyright</a></li>
77
+ </ul>
78
+ </details>
45
79
 
46
80
  ## Installation
47
81
 
@@ -63,6 +97,24 @@ and run
63
97
  $ bundle
64
98
  ```
65
99
 
100
+ ## Localization
101
+
102
+ Currently gem supports two different languages, Turkish and English. English is default, if no action taken.
103
+
104
+ Language can be easily changed by ```change_locale``` method. Valid parameters are 'tr' for Turkish and 'en' for English.
105
+
106
+ ```rb
107
+ TurkishCities.change_locale('tr') # => "Dil Türkçe olarak ayarlandı."
108
+ ```
109
+
110
+ After changing language all errors and result sets will be in desired language
111
+
112
+ ```rb
113
+ TurkishCities.list_districts('Eskişehirrr') # => "'Eskişehirrr' ile bir şehir bulunamadı"
114
+ TurkishCities.distance_between('kirsehir', 'Ordu', 'land')
115
+ # => [533, "Kırşehir ile Ordu arasındaki karayolu mesafesi 533 km"]
116
+ ```
117
+
66
118
  ## Documentation
67
119
 
68
120
  With using irb just require gem and start using
@@ -75,6 +127,9 @@ require 'turkish_cities'
75
127
 
76
128
  There are 81 cities in Turkey. By calling a plate number between 1-81 will give city_name.
77
129
 
130
+ <details>
131
+ <summary>Expand</summary>
132
+
78
133
  ```rb
79
134
  TurkishCities.find_name_by_plate_number(26) # => "Eskişehir"
80
135
  TurkishCities.find_name_by_plate_number(7) # => "Antalya"
@@ -83,11 +138,15 @@ TurkishCities.find_name_by_plate_number(43.0) # => "Kütahya"
83
138
  TurkishCities.find_name_by_plate_number('78') # => "Karabük"
84
139
  TurkishCities.find_name_by_plate_number(100) # => 'Given value [100] is outside bounds of 1 to 81.'
85
140
  ```
141
+ </details>
86
142
 
87
143
  ### Finding city name by phone code
88
144
 
89
145
  There are 82 phone codes for each city in Turkey (Istanbul is an exception with different phone codes for Anatolian side and European side). By calling a phone code between 212-488 will give city_name. All phone codes ending with even numbers. So sending an odd number will give an error without searching.
90
146
 
147
+ <details>
148
+ <summary>Expand</summary>
149
+
91
150
  ```rb
92
151
  TurkishCities.find_name_by_phone_code(312) # => "Ankara"
93
152
  TurkishCities.find_name_by_phone_code(242) # => "Antalya"
@@ -99,11 +158,15 @@ TurkishCities.find_name_by_phone_code(360) # => 'Couldn't find city name with
99
158
  TurkishCities.find_name_by_phone_code(0) # => 'Given value [0] is outside bounds of 212 to 488.'
100
159
  TurkishCities.find_name_by_phone_code(213) # => 'Given value [213] must be an even number.'
101
160
  ```
161
+ </details>
102
162
 
103
163
  ### Finding plate number by city name
104
164
 
105
165
  City name can be given case and turkish character insensitive.
106
166
 
167
+ <details>
168
+ <summary>Expand</summary>
169
+
107
170
  ```rb
108
171
  TurkishCities.find_plate_number_by_name('Ankara') # => 6
109
172
  TurkishCities.find_plate_number_by_name('Eskişehir') # => 26
@@ -112,11 +175,15 @@ TurkishCities.find_plate_number_by_name('Istanbul') # => 34
112
175
  TurkishCities.find_plate_number_by_name('kirsehir') # => 40
113
176
  TurkishCities.find_plate_number_by_name('falansehir') # => "Couldn't find city name with 'falansehir'"
114
177
  ```
178
+ </details>
115
179
 
116
180
  ### Finding phone code by city name
117
181
 
118
182
  City name can be given case and turkish character insensitive.
119
183
 
184
+ <details>
185
+ <summary>Expand</summary>
186
+
120
187
  ```rb
121
188
  TurkishCities.find_phone_code_by_name('Ankara') # => 312
122
189
  TurkishCities.find_phone_code_by_name('Eskişehir') # => 222
@@ -125,19 +192,27 @@ TurkishCities.find_phone_code_by_name('Istanbul') # => [212, 216]
125
192
  TurkishCities.find_phone_code_by_name('kirsehir') # => 386
126
193
  TurkishCities.find_phone_code_by_name('filansehir') # => "Couldn't find city name with 'filansehir'"
127
194
  ```
195
+ </details>
128
196
 
129
197
  ### Listing all cities
130
198
 
131
199
  By default cities will be listed by their plate number ascending.
132
200
 
201
+ <details>
202
+ <summary>Expand</summary>
203
+
133
204
  ```rb
134
205
  TurkishCities.list_cities # => ["Adana", "Adıyaman" ... "Kilis", "Osmaniye", "Düzce"]
135
206
  ```
207
+ </details>
136
208
 
137
209
  ### Listing all cities with only name
138
210
 
139
211
  While listing cities three additional parameters can be sent ```alphabetically_sorted```, ```metropolitan_municipality``` and ```region```. All parameters can be sent separately and together.
140
212
 
213
+ <details>
214
+ <summary>Expand</summary>
215
+
141
216
  ```rb
142
217
  TurkishCities.list_cities({ alphabetically_sorted: true })
143
218
  # => ["Adana", "Adıyaman" ... "Yalova", "Yozgat", "Zonguldak"]
@@ -152,11 +227,15 @@ TurkishCities.list_cities({ metropolitan_municipality: true, region: 'Karadeniz'
152
227
  TurkishCities.list_cities({ alphabetically_sorted: true, metropolitan_municipality: true })
153
228
  # => ["Adana", "Ankara" ... "Tekirdağ", "Trabzon", "Van"]
154
229
  ```
230
+ </details>
155
231
 
156
232
  ### Listing all cities with other parameters
157
233
 
158
234
  While listing cities ```with``` parameter can be used for listing cities with other attributes. These parameters are ```alphabetically_sorted```, ```metropolitan_municipality``` and ```region```. All parameters can be sent separately and together.
159
235
 
236
+ <details>
237
+ <summary>Expand</summary>
238
+
160
239
  ```rb
161
240
  TurkishCities.list_cities({ alphabetically_sorted: true, with: { phone_code: true } })
162
241
  # => [{:name=>"Adana", :phone_code=>322}, {:name=>"Adıyaman", :phone_code=>416}, {:name=>"Afyon", :phone_code=>272} .
@@ -170,11 +249,15 @@ TurkishCities.list_cities({ metropolitan_municipality: true, region: 'Karadeniz'
170
249
  # :metropolitan_municipality_since=>1993, :region=>"Karadeniz"}, {:name=>"Trabzon", :plate_number=>61,
171
250
  # :phone_code=>462, :metropolitan_municipality_since=>2012, :region=>"Karadeniz"}]
172
251
  ```
252
+ </details>
173
253
 
174
254
  ### Listing all districts of given city
175
255
 
176
256
  City name can be given case and turkish character insensitive. Listing of districts are alphabetically sorted.
177
257
 
258
+ <details>
259
+ <summary>Expand</summary>
260
+
178
261
  ```rb
179
262
  TurkishCities.list_districts('Ankara')
180
263
  # => ["Akyurt", "Altındağ" ... "Sincan", "Şereflikoçhisar", "Yenimahalle"]
@@ -189,11 +272,15 @@ TurkishCities.list_districts('Istanbul').length
189
272
  TurkishCities.list_districts('filansehir')
190
273
  # => "Couldn't find city name with 'filansehir'"
191
274
  ```
275
+ </details>
192
276
 
193
277
  ### Listing all subdistricts of given city and district
194
278
 
195
279
  City name can be given case and turkish character insensitive. District name should be case and turkish character sensitive.(Correct district names can be obtained by ```list_districts``` method.) Listing of subdistricts are alphabetically sorted.
196
280
 
281
+ <details>
282
+ <summary>Expand</summary>
283
+
197
284
  ```rb
198
285
  TurkishCities.list_subdistricts('Adana', 'Seyhan')
199
286
  # => ["Akkapı", "Denizli" ... "Yeşiloba", "Yeşilyurt", "Ziyapaşa"]
@@ -207,12 +294,17 @@ TurkishCities.list_subdistricts('İstanbul', 'Kadılarköyü')
207
294
  # => "Couldn't find district name with 'Kadılarköyü' of 'İstanbul'"
208
295
  ```
209
296
 
297
+ </details>
298
+
210
299
  ### Listing all neighborhoods of given city and district
211
300
 
212
301
  ### With subdistrict info
213
302
 
214
303
  City name can be given case and turkish character insensitive. District name and subdistrict name should be case and turkish character sensitive.(Correct district names can be obtained by the ```list_districts``` method. Correct subdistrict names can be obtained by ```list_subdistricts``` method.) Listings of neighborhoods are alphabetically sorted.
215
304
 
305
+ <details>
306
+ <summary>Expand</summary>
307
+
216
308
  ```rb
217
309
  TurkishCities.list_neighborhoods('Adana', 'Seyhan', 'Emek')
218
310
  # => ["Emek Mah", "Ova Mah", "Şakirpaşa Mah", "Uçak Mah"]
@@ -225,6 +317,7 @@ TurkishCities.list_neighborhoods('Adana', 'Beşiktaş', 'Emek')
225
317
  TurkishCities.list_neighborhoods('Eskişehir', 'Odunpazarı', 'Büyükkkkkdere')
226
318
  # => "Couldn't find subdistrict with 'Büyükkkkkdere' of 'Odunpazarı'/'Eskişehir'"
227
319
  ```
320
+ </details>
228
321
 
229
322
  ### Without subdistrict info
230
323
 
@@ -232,6 +325,9 @@ Also ```list_neighborhoods``` can work without subdistrict information. This tim
232
325
 
233
326
  City name can be given case and turkish character insensitive. District name should be case and turkish character sensitive.(Correct district names can be obtained by the ```list_districts``` method.) Listings of neighborhoods are alphabetically sorted.
234
327
 
328
+ <details>
329
+ <summary>Expand</summary>
330
+
235
331
  ```rb
236
332
  TurkishCities.list_neighborhoods('Adana', 'Seyhan')
237
333
  # => ["2000 Evler Mah", "Ahmet Remzi Yüreğir Mah", "Akkapı Mah" ... "Zeytinli Mah", "Ziyapaşa Mah"]
@@ -242,11 +338,15 @@ TurkishCities.list_neighborhoods('Istanbul', 'Beşiktaş')
242
338
  TurkishCities.list_neighborhoods('İstanbul', 'filanmevki')
243
339
  # => "Couldn't find district name with 'filanmevki' of 'İstanbul'"
244
340
  ```
341
+ </details>
245
342
 
246
343
  ### Finding city, district and subdistrict name by postcode
247
344
 
248
345
  In Turkey postcodes are uniq for subdistricts. Basically when a postcode is search through ```find_by_postcode``` it will give city, district and subdistrict information of postcode if valid and found
249
346
 
347
+ <details>
348
+ <summary>Expand</summary>
349
+
250
350
  ```rb
251
351
  TurkishCities.find_by_postcode(34380) # => ["İstanbul", "Şişli", "Cumhuriyet"]
252
352
  TurkishCities.find_by_postcode(34433) # => ["İstanbul", "Beyoğlu", "Cihangir"]
@@ -254,6 +354,95 @@ TurkishCities.find_by_postcode('26040') # => ["Eskişehir", "Odunpazarı", "Bü
254
354
  TurkishCities.find_by_postcode(34382) # => "Couldn't find any subdistrict with postcode '34382'"
255
355
  TurkishCities.find_by_postcode('100000') # => Given value [100000] is outside bounds of 1010 to 81952.
256
356
  ```
357
+ </details>
358
+
359
+ ### Finding city name with population data
360
+
361
+ ### Exact search
362
+
363
+ Search city name with exact population
364
+
365
+ <details>
366
+ <summary>Expand</summary>
367
+
368
+ ```rb
369
+ TurkishCities.find_by_population('exact', 15840900)
370
+ # => ["İstanbul"]
371
+ TurkishCities.find_by_population('exatc', 2130432)
372
+ # => "Population type 'exatc' is unsupported"
373
+ TurkishCities.find_by_population('exact', 10432)
374
+ # => []
375
+ TurkishCities.find_by_population('exact', 22130432)
376
+ # => []
377
+ ```
378
+ </details>
379
+
380
+ ### Below given
381
+
382
+ Search city name with below population
383
+
384
+ <details>
385
+ <summary>Expand</summary>
386
+
387
+ ```rb
388
+ TurkishCities.find_by_population('below', 86000)
389
+ # => ["Tunceli", "Bayburt"]
390
+ TurkishCities.find_by_population('below', 500000)
391
+ # => ["Amasya", "Artvin" ... "Kilis", "Düzce"]
392
+ TurkishCities.find_by_population('below', 5000000)
393
+ # => ["Adana", "Adıyaman" ... "Kilis", "Osmaniye", "Düzce"]
394
+ TurkishCities.find_by_population('woleb', 2130432)
395
+ # => "Population type 'woleb' is unsupported"
396
+ TurkishCities.find_by_population('below', 10432)
397
+ # => []
398
+ TurkishCities.find_by_population('below', 22130432)
399
+ # => []
400
+ ```
401
+ </details>
402
+
403
+ ### Above given
404
+
405
+ Search city name with above population
406
+
407
+ <details>
408
+ <summary>Expand</summary>
409
+
410
+ ```rb
411
+ TurkishCities.find_by_population('above', 860000)
412
+ # => ["Adana", "Ankara" ... "Şanlıurfa", "Van"]
413
+ TurkishCities.find_by_population('above', 2500000)
414
+ # => ["Ankara", "Antalya", "Bursa", "İstanbul", "İzmir"]
415
+ TurkishCities.find_by_population('above', 5000000)
416
+ # => ["Ankara", "İstanbul"]
417
+ TurkishCities.find_by_population('abov', 2130432)
418
+ # => "Population type 'abov' is unsupported"
419
+ TurkishCities.find_by_population('above', 10432)
420
+ # => []
421
+ TurkishCities.find_by_population('above', 22130432)
422
+ # => []
423
+ ```
424
+ </details>
425
+
426
+ ### Between search
427
+
428
+ Search city name with between population
429
+
430
+ <details>
431
+ <summary>Expand</summary>
432
+
433
+ ```rb
434
+ TurkishCities.find_by_population('between', 15840900, 3000000)
435
+ # => ["Ankara", "Bursa", "İzmir"]
436
+ TurkishCities.find_by_population('between', 828369, 985732)
437
+ # => ["Eskişehir", "Mardin"]
438
+ TurkishCities.find_by_population('between', 2130432, 3500000)
439
+ # => ["Adana", "Antalya", "Bursa", "Konya", "Şanlıurfa"]
440
+ TurkishCities.find_by_population('between', 10432, 100000)
441
+ # => []
442
+ TurkishCities.find_by_population('between', 2130432, 34000000)
443
+ # => []
444
+ ```
445
+ </details>
257
446
 
258
447
  ### Finding travel distance and time estimation between two cities
259
448
 
@@ -261,6 +450,9 @@ TurkishCities.find_by_postcode('100000') # => Given value [100000] is outside bo
261
450
 
262
451
  City names can be given case and turkish character insensitive. Travel method should be lower case. Array with 2 elements will be returned. First element is distance between cities in kilometers and the second element is the description created by the first element.
263
452
 
453
+ <details>
454
+ <summary>Expand</summary>
455
+
264
456
  ```rb
265
457
  TurkishCities.distance_between('Eskişehir', 'Kastamonu', 'land')
266
458
  # => [480, "Land travel distance between Eskişehir and Kastamonu is 480 km."]
@@ -275,11 +467,15 @@ TurkishCities.distance_between('Adana', 'Adıyaman', 'time')
275
467
  TurkishCities.distance_between('filansa', 'falansa', 'land')
276
468
  # => "Couldn't find cities combination with 'filansa/falansa'"
277
469
  ```
470
+ </details>
278
471
 
279
472
  ### By air
280
473
 
281
474
  City names can be given case and turkish character insensitive. Travel method should be lower case. Array with 3 elements will be returned. First element is distance between cities in kilometers, the second element is estimated travel time and the last element is the description created by the first two elements.
282
475
 
476
+ <details>
477
+ <summary>Expand</summary>
478
+
283
479
  ```rb
284
480
  TurkishCities.distance_between('Eskişehir', 'Kastamonu', 'air')
285
481
  # => [327.74, 62, "Air travel distance between Eskişehir and Kastamonu is 327.74 km. Estimated air travel would take 62 minutes."]
@@ -294,6 +490,7 @@ TurkishCities.distance_between('Adana', 'Adıyaman', 'time')
294
490
  TurkishCities.distance_between('filansa', 'falansa', 'air')
295
491
  # => "Couldn't find cities combination with 'filansa/falansa'"
296
492
  ```
493
+ </details>
297
494
 
298
495
  ## Data sources
299
496
 
@@ -303,11 +500,12 @@ All information related with cities can be found at:
303
500
  https://tr.wikipedia.org/wiki/{#city_name_here}
304
501
  ```
305
502
 
306
- Districts, subdisctricts, neighborhoods and postcodes can be found at:
503
+ Districts, subdisctricts, neighborhoods and postcodes information can be found at:
307
504
 
308
505
  ```
309
506
  https://postakodu.ptt.gov.tr/
310
507
  ```
508
+ All districts/subdistricts are up to date at: 23 January 2022 with using PTT file released at 22 November 2021
311
509
 
312
510
  Land distance information can be found at:
313
511
 
@@ -315,13 +513,20 @@ Land distance information can be found at:
315
513
  https://www.kgm.gov.tr/SiteCollectionDocuments/KGMdocuments/Root/Uzakliklar/ilmesafe.xls
316
514
  ```
317
515
 
516
+ Population of cities are up to date as 15 February 2022 as using February 2022 report of Türkiye İstatistik Kurumu (TÜİK) / Turkish Statistical Institute (TURKSTAT)
517
+
518
+ Statistics for gem can be found at:
519
+ ```
520
+ https://bestgems.org/gems/turkish_cities
521
+ ```
522
+
318
523
  ## Compatibility
319
524
 
320
525
  | Ruby Version | Supported |
321
526
  | ------------ | ------------------ |
322
- | 2.7.1 | :white_check_mark: |
323
- | 2.6.6 | :white_check_mark: |
324
- | 2.5.8 | :white_check_mark: |
527
+ | 2.7.x | :white_check_mark: |
528
+ | 2.6.x | :white_check_mark: |
529
+ | 2.5.x | :white_check_mark: |
325
530
  | < 2.5.1 | :x: |
326
531
 
327
532
  - TurkishCities heavily depends on ```:turkic``` case mapping support of Ruby string downcase method. Below Ruby version 2.5.1 some functions will run buggy/false or even won't run at all.
@@ -329,7 +534,6 @@ https://www.kgm.gov.tr/SiteCollectionDocuments/KGMdocuments/Root/Uzakliklar/ilme
329
534
  ## Roadmap
330
535
 
331
536
  - Add missing sea travel method
332
- - Add localization to gem
333
537
  - Refactor tests (separate test suites with more edge case tests)
334
538
 
335
539
  ## Contributing
@@ -359,5 +563,5 @@ The logo is licensed under a
359
563
 
360
564
  ## Copyright
361
565
 
362
- Copyright (c) 2020 Semih Arslanoglu. See [LICENSE.txt](LICENSE.txt) for
566
+ Copyright (c) 2020 - 2022 Semih Arslanoglu. See [LICENSE.txt](LICENSE.txt) for
363
567
  further details.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: %i[rubocop spec]
@@ -0,0 +1,19 @@
1
+ en:
2
+ description_text:
3
+ air_travel: "Air travel distance between %{first_city} and %{second_city} is %{distance} km. Estimated air travel would take %{duration} minutes"
4
+ land_travel: "Land travel distance between %{first_city} and %{second_city} is %{distance} km"
5
+ errors:
6
+ cities_not_found_error: "Couldn't find cities combination with '%{first}/%{second}'"
7
+ city_not_found_error: "Couldn't find city name with '%{input}'"
8
+ city_population_not_found_error: "Couldn't find any city with population data"
9
+ district_not_found_error: "Couldn't find district name with '%{district_input}' of '%{city_input}'"
10
+ not_even_input: "Given value [%{input}] must be an even number"
11
+ outside_bounds: "Given value [%{input}] is outside bounds of %{min} to %{max}"
12
+ postcode_not_found_error: "Couldn't find any subdistrict with postcode '%{postcode_input}'"
13
+ subdistrict_not_found_error: "Couldn't find subdistrict with '%{subdistrict_input}' of '%{district_input}'/'%{city_input}'"
14
+ unsupported_population_type: "Population type '%{input}' is unsupported"
15
+ unsupported_travel_method: "Travel method '%{input}' is unsupported"
16
+ language:
17
+ errors:
18
+ unsupported_language_code: "Unsupported language code. Please use 'tr' for Turkish, 'en' for English"
19
+ success: "Language set to English"
@@ -0,0 +1,19 @@
1
+ tr:
2
+ description_text:
3
+ air_travel: "%{first_city} ile %{second_city} arasındaki havayolu mesafesi %{distance} km. Tahmini uçuş süresi %{duration} dakikadır"
4
+ land_travel: "%{first_city} ile %{second_city} arasındaki karayolu mesafesi %{distance} km"
5
+ errors:
6
+ cities_not_found_error: "'%{first}/%{second}' ile şehir kombinasyonu bulunamadı"
7
+ city_not_found_error: "'%{input}' ile bir şehir bulunamadı"
8
+ city_population_not_found_error: "Verilen nüfus verisi ile şehir bulunamadı"
9
+ district_not_found_error: "'%{city_input}' şehrine ait '%{district_input}' ilçesi ile bir kayıt bulunamadı"
10
+ not_even_input: "Girilen değer [%{input}] çift sayı olmalı"
11
+ outside_bounds: "Girilen değer [%{input}] %{min} ile %{max} değerleri dışında"
12
+ postcode_not_found_error: "'%{postcode_input}' posta kodu ile kayıt bulunamadı"
13
+ subdistrict_not_found_error: "'%{subdistrict_input}' ile '%{district_input}'/'%{city_input}' ait bir kayıt bulunamdı"
14
+ unsupported_population_type: "'%{input}' ile arama methodu desteklenmiyor"
15
+ unsupported_travel_method: "'%{input}' yolculuk methodu desteklenmiyor"
16
+ language:
17
+ errors:
18
+ unsupported_language_code: "Desteklenmeyen dil kodu. Lütfen Türkçe için 'tr', İngilizce için 'en' kullanınız"
19
+ success: "Dil Türkçe olarak ayarlandı"
@@ -8,8 +8,6 @@ require_relative '../turkish_cities/helpers/decomposer_helper'
8
8
  class City
9
9
  include DecomposerHelper
10
10
 
11
- I18n.enforce_available_locales = false
12
-
13
11
  file_path = File.join(File.dirname(__FILE__), 'data/cities.yaml')
14
12
  CITY_LIST = YAML.load_file(file_path)
15
13
 
@@ -67,7 +65,7 @@ class City
67
65
  def check_phone_code(input)
68
66
  return if input.to_i.even?
69
67
 
70
- raise ArgumentError, "Given value [#{input}] must be an even number."
68
+ raise ArgumentError, I18n.t('errors.not_even_input', input: input)
71
69
  end
72
70
 
73
71
  def filter_metropolitan_municipalities(city_list)