turkish_cities 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +5 -0
- data/.hound.yml +1 -1
- data/.older.rubocop.yml +23 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +3 -5
- data/README.md +155 -31
- data/lib/turkish_cities/city.rb +15 -27
- data/lib/turkish_cities/data/cities.yaml +134 -1
- data/lib/turkish_cities/data/districts/adana.yaml +1043 -0
- data/lib/turkish_cities/data/districts/adiyaman.yaml +1243 -0
- data/lib/turkish_cities/data/districts/afyon.yaml +1253 -0
- data/lib/turkish_cities/data/districts/agri.yaml +1038 -0
- data/lib/turkish_cities/data/districts/aksaray.yaml +491 -0
- data/lib/turkish_cities/data/districts/amasya.yaml +753 -0
- data/lib/turkish_cities/data/districts/ankara.yaml +1712 -0
- data/lib/turkish_cities/data/districts/antalya.yaml +1114 -0
- data/lib/turkish_cities/data/districts/ardahan.yaml +396 -0
- data/lib/turkish_cities/data/districts/artvin.yaml +1956 -0
- data/lib/turkish_cities/data/districts/aydin.yaml +761 -0
- data/lib/turkish_cities/data/districts/balikesir.yaml +1338 -0
- data/lib/turkish_cities/data/districts/bartin.yaml +1065 -0
- data/lib/turkish_cities/data/districts/batman.yaml +790 -0
- data/lib/turkish_cities/data/districts/bayburt.yaml +263 -0
- data/lib/turkish_cities/data/districts/bilecik.yaml +425 -0
- data/lib/turkish_cities/data/districts/bingol.yaml +1159 -0
- data/lib/turkish_cities/data/districts/bitlis.yaml +818 -0
- data/lib/turkish_cities/data/districts/bolu.yaml +1730 -0
- data/lib/turkish_cities/data/districts/burdur.yaml +592 -0
- data/lib/turkish_cities/data/districts/bursa.yaml +1266 -0
- data/lib/turkish_cities/data/districts/canakkale.yaml +1035 -0
- data/lib/turkish_cities/data/districts/cankiri.yaml +719 -0
- data/lib/turkish_cities/data/districts/corum.yaml +1576 -0
- data/lib/turkish_cities/data/districts/denizli.yaml +724 -0
- data/lib/turkish_cities/data/districts/diyarbakir.yaml +1132 -0
- data/lib/turkish_cities/data/districts/duzce.yaml +756 -0
- data/lib/turkish_cities/data/districts/edirne.yaml +457 -0
- data/lib/turkish_cities/data/districts/elazig.yaml +1560 -0
- data/lib/turkish_cities/data/districts/erzincan.yaml +1086 -0
- data/lib/turkish_cities/data/districts/erzurum.yaml +1278 -0
- data/lib/turkish_cities/data/districts/eskisehir.yaml +673 -0
- data/lib/turkish_cities/data/districts/gaziantep.yaml +872 -0
- data/lib/turkish_cities/data/districts/giresun.yaml +2753 -0
- data/lib/turkish_cities/data/districts/gumushane.yaml +1185 -0
- data/lib/turkish_cities/data/districts/hakkari.yaml +478 -0
- data/lib/turkish_cities/data/districts/hatay.yaml +680 -0
- data/lib/turkish_cities/data/districts/igdir.yaml +272 -0
- data/lib/turkish_cities/data/districts/isparta.yaml +676 -0
- data/lib/turkish_cities/data/districts/istanbul.yaml +1812 -0
- data/lib/turkish_cities/data/districts/izmir.yaml +1657 -0
- data/lib/turkish_cities/data/districts/kahramanmaras.yaml +776 -0
- data/lib/turkish_cities/data/districts/karabuk.yaml +1171 -0
- data/lib/turkish_cities/data/districts/karaman.yaml +477 -0
- data/lib/turkish_cities/data/districts/kars.yaml +572 -0
- data/lib/turkish_cities/data/districts/kastamonu.yaml +4485 -0
- data/lib/turkish_cities/data/districts/kayseri.yaml +852 -0
- data/lib/turkish_cities/data/districts/kilis.yaml +328 -0
- data/lib/turkish_cities/data/districts/kirikkale.yaml +423 -0
- data/lib/turkish_cities/data/districts/kirklareli.yaml +384 -0
- data/lib/turkish_cities/data/districts/kirsehir.yaml +475 -0
- data/lib/turkish_cities/data/districts/kocaeli.yaml +597 -0
- data/lib/turkish_cities/data/districts/konya.yaml +1418 -0
- data/lib/turkish_cities/data/districts/kutahya.yaml +1042 -0
- data/lib/turkish_cities/data/districts/malatya.yaml +828 -0
- data/lib/turkish_cities/data/districts/manisa.yaml +1318 -0
- data/lib/turkish_cities/data/districts/mardin.yaml +762 -0
- data/lib/turkish_cities/data/districts/mersin.yaml +1013 -0
- data/lib/turkish_cities/data/districts/mugla.yaml +622 -0
- data/lib/turkish_cities/data/districts/mus.yaml +749 -0
- data/lib/turkish_cities/data/districts/nevsehir.yaml +481 -0
- data/lib/turkish_cities/data/districts/nigde.yaml +437 -0
- data/lib/turkish_cities/data/districts/ordu.yaml +857 -0
- data/lib/turkish_cities/data/districts/osmaniye.yaml +655 -0
- data/lib/turkish_cities/data/districts/rize.yaml +1447 -0
- data/lib/turkish_cities/data/districts/sakarya.yaml +744 -0
- data/lib/turkish_cities/data/districts/samsun.yaml +1363 -0
- data/lib/turkish_cities/data/districts/sanliurfa.yaml +1505 -0
- data/lib/turkish_cities/data/districts/siirt.yaml +579 -0
- data/lib/turkish_cities/data/districts/sinop.yaml +2061 -0
- data/lib/turkish_cities/data/districts/sirnak.yaml +404 -0
- data/lib/turkish_cities/data/districts/sivas.yaml +2476 -0
- data/lib/turkish_cities/data/districts/tekirdag.yaml +436 -0
- data/lib/turkish_cities/data/districts/tokat.yaml +1553 -0
- data/lib/turkish_cities/data/districts/trabzon.yaml +794 -0
- data/lib/turkish_cities/data/districts/tunceli.yaml +1074 -0
- data/lib/turkish_cities/data/districts/usak.yaml +735 -0
- data/lib/turkish_cities/data/districts/van.yaml +754 -0
- data/lib/turkish_cities/data/districts/yalova.yaml +151 -0
- data/lib/turkish_cities/data/districts/yozgat.yaml +939 -0
- data/lib/turkish_cities/data/districts/zonguldak.yaml +1599 -0
- data/lib/turkish_cities/data/neighborhoods_parser.rb +52 -0
- data/lib/turkish_cities/district.rb +61 -0
- data/lib/turkish_cities/helpers/decomposer_helper.rb +92 -0
- data/lib/turkish_cities/postcode.rb +27 -0
- data/lib/turkish_cities/version.rb +1 -1
- data/lib/turkish_cities.rb +20 -2
- data/turkish_cities.gemspec +1 -1
- metadata +90 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 528b791fc697635aaedf2ea43825b172f02271f452256c6a3886fb74c8971a83
|
|
4
|
+
data.tar.gz: d6e52070ceaed57ff61fa8725e80a2d5459aefce48c0787bfd0c87a7705c3877
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee0223deae4c3907f26e1769ab57e19f8b901873efa532aa8be31fec3cfe27ce22ebb32fd0d24ebf99d7ec3a17abfc26f3c6061b05782a9cfb376de26ae18b18
|
|
7
|
+
data.tar.gz: 9a10b09a78d230af8e57dafd1609ef3246de8e3ceb45c610132567553d519b6cc6535e7a76e38febedb0547dc5a018683456405ac56892b557ceb788449c02e6
|
data/.codeclimate.yml
ADDED
data/.hound.yml
CHANGED
data/.older.rubocop.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5.1
|
|
3
|
+
Exclude:
|
|
4
|
+
- 'Gemfile'
|
|
5
|
+
- 'turkish_cities.gemspec'
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 100
|
|
8
|
+
Metrics/AbcSize:
|
|
9
|
+
Max: 20
|
|
10
|
+
Metrics/BlockLength:
|
|
11
|
+
ExcludedMethods: ['describe', 'context']
|
|
12
|
+
Metrics/MethodLength:
|
|
13
|
+
Max: 15
|
|
14
|
+
Style/Documentation:
|
|
15
|
+
Enabled: false
|
|
16
|
+
Style/HashEachMethods:
|
|
17
|
+
Enabled: true
|
|
18
|
+
Style/HashTransformKeys:
|
|
19
|
+
Description: 'Prefer `transform_keys` over `each_with_object` and `map`.'
|
|
20
|
+
Enabled: true
|
|
21
|
+
Style/HashTransformValues:
|
|
22
|
+
Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
|
|
23
|
+
Enabled: true
|
data/.rubocop.yml
CHANGED
|
@@ -3,6 +3,8 @@ AllCops:
|
|
|
3
3
|
Exclude:
|
|
4
4
|
- 'Gemfile'
|
|
5
5
|
- 'turkish_cities.gemspec'
|
|
6
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
|
7
|
+
Enabled: true
|
|
6
8
|
Layout/LineLength:
|
|
7
9
|
Max: 100
|
|
8
10
|
Layout/SpaceAroundMethodCallOperator:
|
|
@@ -11,8 +13,12 @@ Lint/RaiseException:
|
|
|
11
13
|
Enabled: true
|
|
12
14
|
Lint/StructNewOverride:
|
|
13
15
|
Enabled: true
|
|
16
|
+
Metrics/AbcSize:
|
|
17
|
+
Max: 20
|
|
14
18
|
Metrics/BlockLength:
|
|
15
19
|
ExcludedMethods: ['describe', 'context']
|
|
20
|
+
Metrics/MethodLength:
|
|
21
|
+
Max: 15
|
|
16
22
|
Style/Documentation:
|
|
17
23
|
Enabled: false
|
|
18
24
|
Style/ExponentialNotation:
|
|
@@ -25,3 +31,5 @@ Style/HashTransformKeys:
|
|
|
25
31
|
Style/HashTransformValues:
|
|
26
32
|
Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
|
|
27
33
|
Enabled: true
|
|
34
|
+
Style/SlicingWithRange:
|
|
35
|
+
Enabled: true
|
data/.travis.yml
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
env:
|
|
2
|
+
global:
|
|
3
|
+
- CC_TEST_REPORTER_ID=23062197f289fd0ae7601ae06c2dd4a0af4e16c436f2428b99ab4b64a7e4a587
|
|
1
4
|
language: ruby
|
|
2
5
|
dist: trusty
|
|
3
6
|
rvm:
|
|
@@ -6,7 +9,13 @@ rvm:
|
|
|
6
9
|
- 2.7
|
|
7
10
|
before_install:
|
|
8
11
|
- gem install bundler
|
|
12
|
+
before_script:
|
|
13
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
|
14
|
+
- chmod +x ./cc-test-reporter
|
|
15
|
+
- ./cc-test-reporter before-build
|
|
9
16
|
script: bundle exec rspec spec
|
|
17
|
+
after_script:
|
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
|
10
19
|
notifications:
|
|
11
20
|
email:
|
|
12
21
|
- arslanoglusemih93@gmail.com
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 (2020-05-18)
|
|
4
|
+
|
|
5
|
+
### New features
|
|
6
|
+
|
|
7
|
+
* [#36](https://github.com/sarslanoglu/turkish_cities/issues/36): Add ```postcode``` class and ```find_by_postcode``` method for finding city, district and subdistrict information by given postcode
|
|
8
|
+
|
|
9
|
+
* [#33](https://github.com/sarslanoglu/turkish_cities/issues/33): Add ```list_neighborhoods``` method for listing neighborhoods and fix some wrong district names
|
|
10
|
+
|
|
11
|
+
* [#29](https://github.com/sarslanoglu/turkish_cities/issues/29): Add ```district``` class and ```list_subdistricts``` method for listing subdistricts
|
|
12
|
+
|
|
13
|
+
* [#27](https://github.com/sarslanoglu/turkish_cities/issues/27): Add all subdistricts and neighborhoods of all Turkish cities
|
|
14
|
+
|
|
15
|
+
* [#25](https://github.com/sarslanoglu/turkish_cities/issues/25): Add district data to each city at yaml file and add new method ```list_districts``` for listing disctricts of cities alphabetically sorted
|
|
16
|
+
|
|
17
|
+
### Changes
|
|
18
|
+
|
|
19
|
+
* [#24](https://github.com/sarslanoglu/turkish_cities/issues/24): Add listing support with ```metropolitan_municipality_since, phone_code, plate_number, region``` to ```listing_cities``` method
|
|
20
|
+
|
|
3
21
|
## 0.1.3 (2020-04-20)
|
|
4
22
|
|
|
5
23
|
### New features
|
data/Gemfile.lock
CHANGED
|
@@ -19,10 +19,9 @@ GEM
|
|
|
19
19
|
docile (1.3.2)
|
|
20
20
|
i18n (1.8.2)
|
|
21
21
|
concurrent-ruby (~> 1.0)
|
|
22
|
-
jaro_winkler (1.5.4)
|
|
23
22
|
json (2.3.0)
|
|
24
23
|
parallel (1.19.1)
|
|
25
|
-
parser (2.7.1.
|
|
24
|
+
parser (2.7.1.2)
|
|
26
25
|
ast (~> 2.4.0)
|
|
27
26
|
rainbow (3.0.0)
|
|
28
27
|
rexml (3.2.4)
|
|
@@ -39,8 +38,7 @@ GEM
|
|
|
39
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
39
|
rspec-support (~> 3.9.0)
|
|
41
40
|
rspec-support (3.9.2)
|
|
42
|
-
rubocop (0.
|
|
43
|
-
jaro_winkler (~> 1.5.1)
|
|
41
|
+
rubocop (0.83.0)
|
|
44
42
|
parallel (~> 1.10)
|
|
45
43
|
parser (>= 2.7.0.1)
|
|
46
44
|
rainbow (>= 2.2.2, < 4.0)
|
|
@@ -68,7 +66,7 @@ DEPENDENCIES
|
|
|
68
66
|
bundler (~> 2.1.4)
|
|
69
67
|
coveralls (~> 0.8.23)
|
|
70
68
|
rspec (~> 3.9.0)
|
|
71
|
-
rubocop (~> 0.
|
|
69
|
+
rubocop (~> 0.83.0)
|
|
72
70
|
turkish_cities!
|
|
73
71
|
|
|
74
72
|
BUNDLED WITH
|
data/README.md
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
# 🏙️ Turkish Cities
|
|
2
2
|
[](https://rubygems.org/gems/turkish_cities)
|
|
3
3
|
[](https://travis-ci.org/sarslanoglu/turkish_cities)
|
|
4
|
-
[](https://codeclimate.com/github/sarslanoglu/turkish_cities)
|
|
5
4
|
[](https://coveralls.io/github/sarslanoglu/turkish_cities?branch=master)
|
|
5
|
+
[](https://codeclimate.com/github/sarslanoglu/turkish_cities/maintainability)
|
|
6
|
+
[](https://codeclimate.com/github/sarslanoglu/turkish_cities/test_coverage)
|
|
6
7
|
[](https://houndci.com)
|
|
7
8
|
[](https://opensource.org/licenses/MIT)
|
|
8
9
|
|
|
9
10
|
**turkish_cities** is a Ruby gem which makes searching and listing Turkish cities easy. https://rubygems.org/gems/turkish_cities
|
|
10
11
|
|
|
12
|
+
## Table of Contents
|
|
13
|
+
* [Installation](#installation)
|
|
14
|
+
* [Documentation](#documentation)
|
|
15
|
+
* [Finding city name by plate number](#finding-city-name-by-plate-number)
|
|
16
|
+
* [Finding city name by phone code](#finding-city-name-by-phone-code)
|
|
17
|
+
* [Finding plate number by city name](#finding-plate-number-by-city-name)
|
|
18
|
+
* [Finding phone code by city name](#finding-phone-code-by-city-name)
|
|
19
|
+
* [Listing all cities](#listing-all-cities)
|
|
20
|
+
* [Listing all cities with only name](#listing-all-cities-with-only-name)
|
|
21
|
+
* [Listing all cities with other parameters](#listing-all-cities-with-other-parameters)
|
|
22
|
+
* [Listing all districts of given city](#listing-all-districts-of-given-city)
|
|
23
|
+
* [Listing all subdistricts of given city and district](#listing-all-subdistricts-of-given-city-and-district)
|
|
24
|
+
* [Listing all neighborhoods of given city and district](#listing-all-neighborhoods-of-given-city-and-district)
|
|
25
|
+
* [With subdistrict info](#with-subdistrict-info)
|
|
26
|
+
* [Without subdistrict info](#ithout-subdistrict-info)
|
|
27
|
+
* [Finding city, district and subdistrict name by postcode](#finding-city-district-and-subdistrict-name-by-postcode)
|
|
28
|
+
* [Compatibility](#compatibility)
|
|
29
|
+
* [Contributing](#contributing)
|
|
30
|
+
* [Changelog](#changelog)
|
|
31
|
+
* [Copyright](#copyright)
|
|
32
|
+
|
|
11
33
|
## Installation
|
|
12
34
|
|
|
13
35
|
Installation is pretty standard:
|
|
@@ -38,56 +60,56 @@ require 'turkish_cities'
|
|
|
38
60
|
|
|
39
61
|
### Finding city name by plate number
|
|
40
62
|
|
|
41
|
-
There are 81 cities in Turkey. By calling a plate number between 1-81 will give city_name
|
|
63
|
+
There are 81 cities in Turkey. By calling a plate number between 1-81 will give city_name.
|
|
42
64
|
|
|
43
65
|
```ruby
|
|
44
|
-
TurkishCities.find_name_by_plate_number(26)
|
|
45
|
-
TurkishCities.find_name_by_plate_number(7)
|
|
66
|
+
TurkishCities.find_name_by_plate_number(26) # => "Eskişehir"
|
|
67
|
+
TurkishCities.find_name_by_plate_number(7) # => "Antalya"
|
|
46
68
|
TurkishCities.find_name_by_plate_number(0007) # => "Antalya"
|
|
47
69
|
TurkishCities.find_name_by_plate_number(43.0) # => "Kütahya"
|
|
48
70
|
TurkishCities.find_name_by_plate_number('78') # => "Karabük"
|
|
49
|
-
TurkishCities.find_name_by_plate_number(100)
|
|
71
|
+
TurkishCities.find_name_by_plate_number(100) # => 'Given value [100] is outside bounds of 1 to 81.'
|
|
50
72
|
```
|
|
51
73
|
|
|
52
74
|
### Finding city name by phone code
|
|
53
75
|
|
|
54
|
-
There are 81 cities in Turkey. By calling a phone code between 212-488 will give city_name. All phone codes are even sending odd number will give error without searching
|
|
76
|
+
There are 81 cities in Turkey. By calling a phone code between 212-488 will give city_name. All phone codes are even sending odd number will give error without searching.
|
|
55
77
|
|
|
56
78
|
```ruby
|
|
57
|
-
TurkishCities.find_name_by_phone_code(312)
|
|
58
|
-
TurkishCities.find_name_by_phone_code(242)
|
|
79
|
+
TurkishCities.find_name_by_phone_code(312) # => "Ankara"
|
|
80
|
+
TurkishCities.find_name_by_phone_code(242) # => "Antalya"
|
|
59
81
|
TurkishCities.find_name_by_phone_code(000222) # => "Eskişehir"
|
|
60
|
-
TurkishCities.find_name_by_phone_code(274.0)
|
|
61
|
-
TurkishCities.find_name_by_phone_code('212')
|
|
62
|
-
TurkishCities.find_name_by_phone_code(216)
|
|
63
|
-
TurkishCities.find_name_by_phone_code(360)
|
|
64
|
-
TurkishCities.find_name_by_phone_code(0)
|
|
65
|
-
TurkishCities.find_name_by_phone_code(213)
|
|
82
|
+
TurkishCities.find_name_by_phone_code(274.0) # => "Kütahya"
|
|
83
|
+
TurkishCities.find_name_by_phone_code('212') # => "İstanbul"
|
|
84
|
+
TurkishCities.find_name_by_phone_code(216) # => "İstanbul"
|
|
85
|
+
TurkishCities.find_name_by_phone_code(360) # => 'Couldn't find city name with phone code 360'
|
|
86
|
+
TurkishCities.find_name_by_phone_code(0) # => 'Given value [0] is outside bounds of 212 to 488.'
|
|
87
|
+
TurkishCities.find_name_by_phone_code(213) # => 'Given value [213] must be an even number.'
|
|
66
88
|
```
|
|
67
89
|
|
|
68
90
|
### Finding plate number by city name
|
|
69
91
|
|
|
70
|
-
City name can be given case and turkish character insensitive
|
|
92
|
+
City name can be given case and turkish character insensitive.
|
|
71
93
|
|
|
72
94
|
```ruby
|
|
73
|
-
TurkishCities.find_plate_number_by_name('Ankara')
|
|
74
|
-
TurkishCities.find_plate_number_by_name('Eskişehir')
|
|
75
|
-
TurkishCities.find_plate_number_by_name('Canakkale')
|
|
76
|
-
TurkishCities.find_plate_number_by_name('Istanbul')
|
|
77
|
-
TurkishCities.find_plate_number_by_name('kirsehir')
|
|
95
|
+
TurkishCities.find_plate_number_by_name('Ankara') # => 6
|
|
96
|
+
TurkishCities.find_plate_number_by_name('Eskişehir') # => 26
|
|
97
|
+
TurkishCities.find_plate_number_by_name('Canakkale') # => 17
|
|
98
|
+
TurkishCities.find_plate_number_by_name('Istanbul') # => 34
|
|
99
|
+
TurkishCities.find_plate_number_by_name('kirsehir') # => 40
|
|
78
100
|
TurkishCities.find_plate_number_by_name('falansehir') # => "Couldn't find city name with 'falansehir'"
|
|
79
101
|
```
|
|
80
102
|
|
|
81
|
-
### Finding phone
|
|
103
|
+
### Finding phone code by city name
|
|
82
104
|
|
|
83
|
-
City name can be given case and turkish character insensitive
|
|
105
|
+
City name can be given case and turkish character insensitive.
|
|
84
106
|
|
|
85
107
|
```ruby
|
|
86
|
-
TurkishCities.find_phone_code_by_name('Ankara')
|
|
87
|
-
TurkishCities.find_phone_code_by_name('Eskişehir')
|
|
88
|
-
TurkishCities.find_phone_code_by_name('Canakkale')
|
|
89
|
-
TurkishCities.find_phone_code_by_name('Istanbul')
|
|
90
|
-
TurkishCities.find_phone_code_by_name('kirsehir')
|
|
108
|
+
TurkishCities.find_phone_code_by_name('Ankara') # => 312
|
|
109
|
+
TurkishCities.find_phone_code_by_name('Eskişehir') # => 222
|
|
110
|
+
TurkishCities.find_phone_code_by_name('Canakkale') # => 286
|
|
111
|
+
TurkishCities.find_phone_code_by_name('Istanbul') # => [212, 216]
|
|
112
|
+
TurkishCities.find_phone_code_by_name('kirsehir') # => 386
|
|
91
113
|
TurkishCities.find_phone_code_by_name('filansehir') # => "Couldn't find city name with 'filansehir'"
|
|
92
114
|
```
|
|
93
115
|
|
|
@@ -99,6 +121,8 @@ By default cities will be listed by their plate number ascending.
|
|
|
99
121
|
TurkishCities.list_cities # => ["Adana", "Adıyaman" ... "Kilis", "Osmaniye", "Düzce"]
|
|
100
122
|
```
|
|
101
123
|
|
|
124
|
+
### Listing all cities with only name
|
|
125
|
+
|
|
102
126
|
While listing cities three additional parameters can be send ```alphabetically_sorted```, ```metropolitan_municipality``` and ```region```. All parameters can be send seperately and together.
|
|
103
127
|
|
|
104
128
|
```ruby
|
|
@@ -116,13 +140,113 @@ TurkishCities.list_cities({ alphabetically_sorted: true, metropolitan_municipali
|
|
|
116
140
|
# => ["Adana", "Ankara" ... "Tekirdağ", "Trabzon", "Van"]
|
|
117
141
|
```
|
|
118
142
|
|
|
143
|
+
### Listing all cities with other parameters
|
|
144
|
+
|
|
145
|
+
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 send seperately and together.
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
TurkishCities.list_cities({ alphabetically_sorted: true, with: { phone_code: true } })
|
|
149
|
+
# => [{:name=>"Adana", :phone_code=>322}, {:name=>"Adıyaman", :phone_code=>416}, {:name=>"Afyon", :phone_code=>272} .
|
|
150
|
+
# .. {:name=>"Yozgat", :phone_code=>354}, {:name=>"Zonguldak", :phone_code=>372}]
|
|
151
|
+
TurkishCities.list_cities({ with: { plate_number: true } })
|
|
152
|
+
# => [{:name=>"Adana", :plate_number=>1}, {:name=>"Adıyaman", :plate_number=>2}, {:name=>"Afyon", :plate_number=>3} .
|
|
153
|
+
# .. {:name=>"Osmaniye", :plate_number=>80}, {:name=>"Düzce", :plate_number=>81}]
|
|
154
|
+
TurkishCities.list_cities({ metropolitan_municipality: true, region: 'Karadeniz', with: { all: true } })
|
|
155
|
+
# => [{:name=>"Ordu", :plate_number=>52, :phone_code=>452, :metropolitan_municipality_since=>2012,
|
|
156
|
+
# :region=>"Karadeniz"},{:name=>"Samsun", :plate_number=>55, :phone_code=>362,
|
|
157
|
+
# :metropolitan_municipality_since=>1993, :region=>"Karadeniz"}, {:name=>"Trabzon", :plate_number=>61,
|
|
158
|
+
# :phone_code=>462, :metropolitan_municipality_since=>2012, :region=>"Karadeniz"}]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Listing all districts of given city
|
|
162
|
+
|
|
163
|
+
City name can be given case and turkish character insensitive. Listing of districts are alphabetically sorted.
|
|
164
|
+
|
|
165
|
+
```ruby
|
|
166
|
+
TurkishCities.list_districts('Ankara')
|
|
167
|
+
# => ["Akyurt", "Altındağ" ... "Sincan", "Şereflikoçhisar", "Yenimahalle"]
|
|
168
|
+
TurkishCities.list_districts('Eskişehir')
|
|
169
|
+
# => ["Alpu", "Beylikova", "Çifteler" ... "Sivrihisar", "Tepebaşı"]
|
|
170
|
+
TurkishCities.list_districts('Canakkale')
|
|
171
|
+
# => ["Ayvacık", "Bayramiç" ... "Lapseki", "Merkez", "Yenice"]
|
|
172
|
+
TurkishCities.list_districts('Bayburt')
|
|
173
|
+
# => ["Aydıntepe", "Demirözü", "Merkez"]
|
|
174
|
+
TurkishCities.list_districts('Istanbul').length
|
|
175
|
+
# => 39
|
|
176
|
+
TurkishCities.list_districts('filansehir')
|
|
177
|
+
# => "Couldn't find city name with 'filansehir'"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Listing all subdistricts of given city and district
|
|
181
|
+
|
|
182
|
+
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.
|
|
183
|
+
|
|
184
|
+
```ruby
|
|
185
|
+
TurkishCities.list_subdistricts('Adana', 'Seyhan')
|
|
186
|
+
# => ["Akkapı", "Denizli" ... "Yeşiloba", "Yeşilyurt", "Ziyapaşa"]
|
|
187
|
+
TurkishCities.list_subdistricts('Eskişehir', 'Odunpazarı')
|
|
188
|
+
# => ["Alanönü", "Arifiye", "Büyükdere" ... "Vişnelik", "Yenikent"]
|
|
189
|
+
TurkishCities.list_subdistricts('Istanbul', 'Beşiktaş')
|
|
190
|
+
# => ["Abbasağa", "Akatlar", "Arnavutköy", "Bebek", "Etiler", "Gayrettepe", "Levazım", "Levent", "Ortaköy", "Türkali"]
|
|
191
|
+
TurkishCities.list_subdistricts('filansehir', 'Beşiktaş')
|
|
192
|
+
# => "Couldn't find district name with 'Beşiktaş' of 'filansehir'"
|
|
193
|
+
TurkishCities.list_subdistricts('İstanbul', 'Kadılarköyü')
|
|
194
|
+
# => "Couldn't find district name with 'Kadılarköyü' of 'İstanbul'"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Listing all neighborhoods of given city and district
|
|
198
|
+
|
|
199
|
+
### With subdistrict info
|
|
200
|
+
|
|
201
|
+
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 ```list_districts``` method. Correct subdistrict names can be obtained by ```list_subdistricts``` method.) Listing of neighborhoods are alphabetically sorted.
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
TurkishCities.list_neighborhoods('Adana', 'Seyhan', 'Emek')
|
|
205
|
+
# => ["Emek Mah", "Ova Mah", "Şakirpaşa Mah", "Uçak Mah"]
|
|
206
|
+
TurkishCities.list_neighborhoods('Eskişehir', 'Odunpazarı', 'Büyükdere')
|
|
207
|
+
# => ["Büyükdere Mah", "Göztepe Mah", "Gültepe Mah", "Yıldıztepe Mah"]
|
|
208
|
+
TurkishCities.list_neighborhoods('Istanbul', 'Beşiktaş', 'Gayrettepe')
|
|
209
|
+
# => ["Balmumcu Mah", "Dikilitaş Mah", "Gayrettepe Mah", "Yıldız Mah"]
|
|
210
|
+
TurkishCities.list_neighborhoods('Adana', 'Beşiktaş', 'Emek')
|
|
211
|
+
# => "Couldn't find district name with 'Beşiktaş' of 'Adana'"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Without subdistrict info
|
|
215
|
+
|
|
216
|
+
Also ```list_neighborhoods``` can work without subdistrict information. This time neighborhoods result will be larger based on searched city and district.
|
|
217
|
+
|
|
218
|
+
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 neighborhoods are alphabetically sorted.
|
|
219
|
+
|
|
220
|
+
```ruby
|
|
221
|
+
TurkishCities.list_neighborhoods('Adana', 'Seyhan')
|
|
222
|
+
# => ["2000 Evler Mah", "Ahmet Remzi Yüreğir Mah", "Akkapı Mah" ... "Zeytinli Mah", "Ziyapaşa Mah"]
|
|
223
|
+
TurkishCities.list_neighborhoods('Eskişehir', 'Odunpazarı')
|
|
224
|
+
# => ["71 Evler Mah", "75. Yıl Osb Mah" ... "Yukarıkalabak Mah", "Yürükkaracaören Mah", "Yürükkırka Mah"]
|
|
225
|
+
TurkishCities.list_neighborhoods('Istanbul', 'Beşiktaş')
|
|
226
|
+
# => ["Abbasağa Mah", "Akat Mah", "Arnavutköy Mah" ... "Türkali Mah", "Ulus Mah", "Vişnezade Mah", "Yıldız Mah"]
|
|
227
|
+
TurkishCities.list_neighborhoods('İstanbul', 'filanmevki')
|
|
228
|
+
# => "Couldn't find district name with 'filanmevki' of 'İstanbul'"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Finding city, district and subdistrict name by postcode
|
|
232
|
+
|
|
233
|
+
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
|
|
234
|
+
|
|
235
|
+
```ruby
|
|
236
|
+
TurkishCities.find_by_postcode(34380) # => ["İstanbul", "Şişli", "Cumhuriyet"]
|
|
237
|
+
TurkishCities.find_by_postcode(34433) # => ["İstanbul", "Beyoğlu", "Cihangir"]
|
|
238
|
+
TurkishCities.find_by_postcode('26040') # => ["Eskişehir", "Odunpazarı", "Büyükdere"]
|
|
239
|
+
TurkishCities.find_by_postcode(34382) # => "Couldn't find any subdistrict with postcode '34382'"
|
|
240
|
+
TurkishCities.find_by_postcode('100000') # => Given value [100000] is outside bounds of 1010 to 81952.
|
|
241
|
+
```
|
|
242
|
+
|
|
119
243
|
## Compatibility
|
|
120
244
|
|
|
121
|
-
- ✅ `2.7.
|
|
122
|
-
- ✅ `2.6.
|
|
123
|
-
- ✅ `2.5.
|
|
245
|
+
- ✅ `2.7.1` (stable)
|
|
246
|
+
- ✅ `2.6.6` (stable)
|
|
247
|
+
- ✅ `2.5.8` (stable)
|
|
124
248
|
|
|
125
|
-
- This gem heavily depends
|
|
249
|
+
- This gem 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.
|
|
126
250
|
|
|
127
251
|
## Contributing
|
|
128
252
|
|
data/lib/turkish_cities/city.rb
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
require 'i18n'
|
|
4
4
|
require 'yaml'
|
|
5
5
|
|
|
6
|
+
require_relative '../turkish_cities/helpers/decomposer_helper'
|
|
7
|
+
|
|
6
8
|
class City
|
|
9
|
+
include DecomposerHelper
|
|
10
|
+
|
|
7
11
|
I18n.enforce_available_locales = false
|
|
8
12
|
|
|
9
13
|
file_path = File.join(File.dirname(__FILE__), 'data/cities.yaml')
|
|
@@ -28,7 +32,7 @@ class City
|
|
|
28
32
|
return city['name']
|
|
29
33
|
end
|
|
30
34
|
end
|
|
31
|
-
|
|
35
|
+
city_not_found_error(phone_code)
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
def find_by_name(city_name, return_type)
|
|
@@ -37,7 +41,7 @@ class City
|
|
|
37
41
|
return return_type == 'plate_number' ? city['plate_number'] : city['phone_code']
|
|
38
42
|
end
|
|
39
43
|
end
|
|
40
|
-
|
|
44
|
+
city_not_found_error(city_name)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def list_cities(options)
|
|
@@ -46,28 +50,25 @@ class City
|
|
|
46
50
|
city_list = filter_metropolitan_municipalities(city_list) if options[:metropolitan_municipality]
|
|
47
51
|
city_list = filter_regions(city_list, options[:region]) if options[:region]
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
options[:alphabetically_sorted] ?
|
|
53
|
+
final_list = prepare_city_list(city_list, options)
|
|
54
|
+
options[:alphabetically_sorted] ? sort_alphabetically(final_list, options) : final_list
|
|
51
55
|
end
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
raise RangeError, "Given value [#{input}] is outside bounds of #{min} to #{max}."
|
|
57
|
+
def list_districts(city_name)
|
|
58
|
+
CITY_LIST.each do |city|
|
|
59
|
+
return city['districts'] if convert_chars(city['name']) == convert_chars(city_name)
|
|
60
|
+
end
|
|
61
|
+
city_not_found_error(city_name)
|
|
59
62
|
end
|
|
60
63
|
|
|
64
|
+
private
|
|
65
|
+
|
|
61
66
|
def check_phone_code(input)
|
|
62
67
|
return if input.to_i.even?
|
|
63
68
|
|
|
64
69
|
raise ArgumentError, "Given value [#{input}] must be an even number."
|
|
65
70
|
end
|
|
66
71
|
|
|
67
|
-
def convert_chars(string)
|
|
68
|
-
I18n.transliterate(string.downcase(:turkic))
|
|
69
|
-
end
|
|
70
|
-
|
|
71
72
|
def filter_metropolitan_municipalities(city_list)
|
|
72
73
|
city_list.map { |city| city unless city['metropolitan_municipality_since'].nil? }.compact
|
|
73
74
|
end
|
|
@@ -76,17 +77,4 @@ class City
|
|
|
76
77
|
region = convert_chars(region.to_s)
|
|
77
78
|
city_list.map { |city| city if convert_chars(city['region']) == region }.compact
|
|
78
79
|
end
|
|
79
|
-
|
|
80
|
-
def prepare_city_list(city_list)
|
|
81
|
-
city_list.map do |city|
|
|
82
|
-
city['name']
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def sort_cities(city_list)
|
|
87
|
-
turkish_alphabet = ' -abcçdefgğhıijklmnoöprsştuüvyz'
|
|
88
|
-
city_list.sort_by do |city|
|
|
89
|
-
city.downcase(:turkic).chars.map { |char| turkish_alphabet.index(char) }
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
80
|
end
|