turkish_cities 0.1.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +5 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/dependabot.yml +20 -0
- data/.github/pull_request_template.md +38 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +8 -18
- data/.travis.yml +9 -0
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +35 -32
- data/README.md +290 -47
- data/config/locales/en.yml +17 -0
- data/config/locales/tr.yml +17 -0
- data/lib/turkish_cities.rb +42 -4
- data/lib/turkish_cities/city.rb +18 -31
- data/lib/turkish_cities/data/cities.yaml +562 -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/distance.rb +134 -0
- data/lib/turkish_cities/district.rb +53 -0
- data/lib/turkish_cities/helpers/decomposer_helper.rb +106 -0
- data/lib/turkish_cities/postcode.rb +25 -0
- data/lib/turkish_cities/version.rb +1 -1
- data/public/assets/img/TurkishCities_darkblue-on-yellow_800X800@3x-8.png +0 -0
- data/public/assets/img/TurkishCities_darkblue-on-yellow_914X343@3x-8.png +0 -0
- data/public/assets/img/TurkishCities_darkblue-on-yellow_horizontal_914X343@3x-8.png +0 -0
- data/public/assets/img/TurkishCities_yellow-on-darkblue_800X800@3x-8.png +0 -0
- data/public/assets/img/TurkishCities_yellow-on-darkblue_914X343@3x-8.png +0 -0
- data/public/assets/img/TurkishCities_yellow-on-darkblue_horizontal_914X343@3x-8.png +0 -0
- data/turkish_cities.gemspec +4 -5
- metadata +114 -14
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require_relative '../helpers/decomposer_helper'
|
7
|
+
|
8
|
+
module NeighborhoodsParser
|
9
|
+
include DecomposerHelper
|
10
|
+
|
11
|
+
district_hash = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
12
|
+
mahalle_array = []
|
13
|
+
last_city = 'Adana'
|
14
|
+
last_district = ''
|
15
|
+
last_subdistrict = ''
|
16
|
+
last_postcode = 1720
|
17
|
+
|
18
|
+
# rubocop:disable Metrics/BlockLength
|
19
|
+
CSV.parse(File.read('ptt_list.csv'), headers: true).each do |row|
|
20
|
+
data_array = row['il;ilçe;semt_bucak_belde;Mahalle;PK'].split(';')
|
21
|
+
|
22
|
+
if data_array[0].downcase(:turkic).strip.capitalize(:turkic) != last_city ||
|
23
|
+
data_array[4].to_i != last_postcode
|
24
|
+
district_hash[last_district][last_subdistrict]['postcode'] = last_postcode
|
25
|
+
district_hash[last_district][last_subdistrict]['neighborhoods'] = mahalle_array
|
26
|
+
mahalle_array = []
|
27
|
+
if data_array[0].downcase(:turkic).strip.capitalize(:turkic) != last_city
|
28
|
+
file_name = create_file_path(last_city)
|
29
|
+
File.write("#{file_name}.yaml", district_hash.to_yaml)
|
30
|
+
district_hash = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
mahalle = []
|
35
|
+
data_array[3].downcase(:turkic).strip.split.each do |word|
|
36
|
+
if word[0] == '('
|
37
|
+
word[1] = word[1].capitalize!(:turkic) unless word[1].to_i.to_s == word[1]
|
38
|
+
else
|
39
|
+
word.capitalize!(:turkic)
|
40
|
+
end
|
41
|
+
mahalle << word
|
42
|
+
end
|
43
|
+
|
44
|
+
mahalle_array << mahalle.join(' ')
|
45
|
+
|
46
|
+
last_city = data_array[0].downcase(:turkic).strip.capitalize(:turkic)
|
47
|
+
last_district = data_array[1].downcase(:turkic).strip.capitalize(:turkic)
|
48
|
+
last_subdistrict = data_array[2].downcase(:turkic).strip.capitalize(:turkic)
|
49
|
+
last_postcode = data_array[4].to_i
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/BlockLength
|
52
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require_relative '../turkish_cities/helpers/decomposer_helper'
|
7
|
+
|
8
|
+
class Distance
|
9
|
+
include DecomposerHelper
|
10
|
+
|
11
|
+
file_path = File.join(File.dirname(__FILE__), 'data/cities.yaml')
|
12
|
+
CITY_LIST = YAML.load_file(file_path)
|
13
|
+
RADIUS_OF_EARTH = 6371 # Earth radius in km is 6371
|
14
|
+
|
15
|
+
def initialize(from, to, travel_method)
|
16
|
+
@from = from
|
17
|
+
@to = to
|
18
|
+
@travel_method = travel_method
|
19
|
+
end
|
20
|
+
|
21
|
+
def distance_between
|
22
|
+
case @travel_method
|
23
|
+
when 'land'
|
24
|
+
distance_between_land
|
25
|
+
when 'sea'
|
26
|
+
distance_between_sea
|
27
|
+
when 'air'
|
28
|
+
distance_between_air
|
29
|
+
else
|
30
|
+
unsupported_travel_method(@travel_method)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def distance_between_land
|
37
|
+
city_array = find_city_attributes
|
38
|
+
case city_array
|
39
|
+
when String
|
40
|
+
city_array
|
41
|
+
when Array
|
42
|
+
results = []
|
43
|
+
results[0] = calculate_land_distance(city_array)
|
44
|
+
results[1] = description_text('Land', city_array, results)
|
45
|
+
results
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def distance_between_sea
|
50
|
+
# TODO
|
51
|
+
end
|
52
|
+
|
53
|
+
def distance_between_air
|
54
|
+
city_array = find_city_attributes
|
55
|
+
case city_array
|
56
|
+
when String
|
57
|
+
city_array
|
58
|
+
when Array
|
59
|
+
results = []
|
60
|
+
results[0] = calculate_flight_distance(city_array).round(2)
|
61
|
+
results[1] = distance_time_estimation(results[0]).to_i
|
62
|
+
results[2] = description_text('Air', city_array, results)
|
63
|
+
results
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_city_attributes
|
68
|
+
from_city = to_city = nil
|
69
|
+
|
70
|
+
CITY_LIST.each do |city|
|
71
|
+
from_city = city if convert_chars(@from) == convert_chars(city['name'])
|
72
|
+
to_city = city if convert_chars(@to) == convert_chars(city['name'])
|
73
|
+
end
|
74
|
+
|
75
|
+
from_city.nil? || to_city.nil? ? cities_not_found_error(@from, @to) : [from_city, to_city]
|
76
|
+
end
|
77
|
+
|
78
|
+
# rubocop:disable Metrics/AbcSize
|
79
|
+
def calculate_land_distance(city_array)
|
80
|
+
# Distance information between cities are kept in yaml files in a plate number order
|
81
|
+
# For example if distance between plate number 10 with plate number 3
|
82
|
+
# Order should be 3 to 10 not 10 to 3
|
83
|
+
if city_array[0]['plate_number'] > city_array[1]['plate_number']
|
84
|
+
return city_array[1]['land_distance'][city_array[0]['plate_number'] - city_array[1]['plate_number'] - 1]
|
85
|
+
end
|
86
|
+
|
87
|
+
city_array[0]['land_distance'][city_array[1]['plate_number'] - city_array[0]['plate_number'] - 1]
|
88
|
+
end
|
89
|
+
# rubocop:enable Metrics/AbcSize
|
90
|
+
|
91
|
+
def degree_to_radian(degree)
|
92
|
+
degree * Math::PI / 180
|
93
|
+
end
|
94
|
+
|
95
|
+
# rubocop:disable Metrics/AbcSize
|
96
|
+
def calculate_flight_distance(city_array)
|
97
|
+
lat_diff = degree_to_radian(city_array[1]['latitude'] - city_array[0]['latitude'])
|
98
|
+
lng_diff = degree_to_radian(city_array[1]['longitude'] - city_array[0]['longitude'])
|
99
|
+
|
100
|
+
from_lat = degree_to_radian(city_array[0]['latitude'])
|
101
|
+
to_lat = degree_to_radian(city_array[1]['latitude'])
|
102
|
+
|
103
|
+
cosines_var = (Math.sin(lat_diff / 2)**2) + ((Math.sin(lng_diff / 2)**2) * (Math.cos(from_lat) * Math.cos(to_lat)))
|
104
|
+
result = 2 * Math.atan2(Math.sqrt(cosines_var), Math.sqrt(1 - cosines_var))
|
105
|
+
RADIUS_OF_EARTH * result
|
106
|
+
end
|
107
|
+
# rubocop:enable Metrics/AbcSize
|
108
|
+
|
109
|
+
# Time estimation for air travel. For planes take-off and landing took nearly same amount.
|
110
|
+
# Longer the distance shorter the time. Flying out at high altitude makes less air resistance / more speed
|
111
|
+
def distance_time_estimation(air_distance)
|
112
|
+
case air_distance
|
113
|
+
when 0..400
|
114
|
+
(air_distance / 10) + 30
|
115
|
+
when 400..1000
|
116
|
+
(air_distance / 11.25) + 30
|
117
|
+
else
|
118
|
+
(air_distance / 12.5) + 25
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def description_text(travel_method, city_array, result_set)
|
123
|
+
if travel_method == 'Air'
|
124
|
+
return I18n.t('description_text.air_travel', first_city: city_array[0]['name'],
|
125
|
+
second_city: city_array[1]['name'],
|
126
|
+
distance: result_set[0],
|
127
|
+
duration: result_set[1])
|
128
|
+
end
|
129
|
+
|
130
|
+
I18n.t('description_text.land_travel', first_city: city_array[0]['name'],
|
131
|
+
second_city: city_array[1]['name'],
|
132
|
+
distance: result_set[0])
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require_relative '../turkish_cities/helpers/decomposer_helper'
|
7
|
+
|
8
|
+
class District
|
9
|
+
include DecomposerHelper
|
10
|
+
|
11
|
+
def initialize(city_name, district_name)
|
12
|
+
@city_name = city_name
|
13
|
+
@district_name = district_name
|
14
|
+
@district_list = create_district_list(city_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def subdistricts
|
18
|
+
return district_not_found_error(@district_name, @city_name) if district_item.nil?
|
19
|
+
|
20
|
+
sort_alphabetically(district_item.keys)
|
21
|
+
end
|
22
|
+
|
23
|
+
def neighborhoods(subdistrict_name)
|
24
|
+
return district_not_found_error(@district_name, @city_name) if district_item.nil?
|
25
|
+
|
26
|
+
neighborhoods = create_neighborhoods(subdistrict_name)
|
27
|
+
neighborhoods.is_a?(Array) ? sort_alphabetically(neighborhoods) : neighborhoods
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_neighborhoods(subdistrict_name)
|
33
|
+
return create_neighborhoods_without_subdistrict_name if subdistrict_name.nil?
|
34
|
+
|
35
|
+
if district_item[subdistrict_name].nil?
|
36
|
+
return subdistrict_not_found_error(subdistrict_name, @district_name, @city_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
create_neighborhoods_with_subdistrict_name(subdistrict_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_neighborhoods_without_subdistrict_name
|
43
|
+
district_item.values.map { |subdistrict| subdistrict['neighborhoods'] }.flatten
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_neighborhoods_with_subdistrict_name(subdistrict_name)
|
47
|
+
district_item[subdistrict_name]['neighborhoods']
|
48
|
+
end
|
49
|
+
|
50
|
+
def district_item
|
51
|
+
@district_list[@district_name]
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DecomposerHelper
|
4
|
+
def check_input_range(input, min, max)
|
5
|
+
return if input.to_i.between?(min, max)
|
6
|
+
|
7
|
+
raise RangeError, I18n.t('errors.outside_bounds', input: input, min: min, max: max)
|
8
|
+
end
|
9
|
+
|
10
|
+
def city_not_found_error(input)
|
11
|
+
I18n.t('errors.city_not_found_error', input: input)
|
12
|
+
end
|
13
|
+
|
14
|
+
def cities_not_found_error(first, second)
|
15
|
+
I18n.t('errors.cities_not_found_error', first: first, second: second)
|
16
|
+
end
|
17
|
+
|
18
|
+
def convert_chars(string)
|
19
|
+
I18n.transliterate(string.downcase(:turkic))
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_district_list(city_name)
|
23
|
+
file_name = create_file_path(city_name)
|
24
|
+
file_path = File.join(File.dirname(__FILE__), "../data/districts/#{file_name}.yaml")
|
25
|
+
begin
|
26
|
+
YAML.load_file(file_path)
|
27
|
+
rescue Errno::ENOENT => e
|
28
|
+
"Caught the exception: #{e}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_file_path(city_name)
|
33
|
+
char_fallbacks = { 'ç' => 'c', 'ğ' => 'g', 'ı' => 'i', 'ö' => 'o', 'ş' => 's', 'ü' => 'u' }
|
34
|
+
city_name.downcase(:turkic).encode('ASCII', 'UTF-8', fallback: char_fallbacks)
|
35
|
+
end
|
36
|
+
|
37
|
+
def district_not_found_error(district_input, city_input)
|
38
|
+
I18n.t('errors.district_not_found_error', district_input: district_input, city_input: city_input)
|
39
|
+
end
|
40
|
+
|
41
|
+
def postcode_not_found_error(postcode_input)
|
42
|
+
I18n.t('errors.postcode_not_found_error', postcode_input: postcode_input)
|
43
|
+
end
|
44
|
+
|
45
|
+
def prepare_city_list(city_list, options)
|
46
|
+
if options[:with]
|
47
|
+
city_list.map do |city|
|
48
|
+
result = {}
|
49
|
+
result[:name] = city['name']
|
50
|
+
|
51
|
+
add_plate_number_if_requested(result, city, options)
|
52
|
+
add_phone_code_if_requested(result, city, options)
|
53
|
+
add_metropolitan_municipality_if_requested(result, city, options)
|
54
|
+
|
55
|
+
result[:region] = city['region'] if options.dig(:with, :region) || options.dig(:with, :all)
|
56
|
+
result
|
57
|
+
end
|
58
|
+
else
|
59
|
+
city_list.map do |city|
|
60
|
+
city['name']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def sort_alphabetically(list, options = nil)
|
66
|
+
turkish_alphabet = ' -0123456789abcçdefgğhıijklmnoöprsştuüvyz'
|
67
|
+
|
68
|
+
list.sort_by do |item|
|
69
|
+
item_to_sort = if options.nil? || options[:with].nil?
|
70
|
+
item
|
71
|
+
else
|
72
|
+
item[:name]
|
73
|
+
end
|
74
|
+
item_to_sort.downcase(:turkic).chars.map { |char| turkish_alphabet.index(char) }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def subdistrict_not_found_error(subdistrict_input, district_input, city_input)
|
79
|
+
I18n.t('errors.subdistrict_not_found_error', subdistrict_input: subdistrict_input, district_input: district_input,
|
80
|
+
city_input: city_input)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def add_plate_number_if_requested(result, city, options = nil)
|
86
|
+
return unless options.dig(:with, :plate_number) || options.dig(:with, :all)
|
87
|
+
|
88
|
+
result[:plate_number] = city['plate_number']
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_phone_code_if_requested(result, city, options = nil)
|
92
|
+
return unless options.dig(:with, :phone_code) || options.dig(:with, :all)
|
93
|
+
|
94
|
+
result[:phone_code] = city['phone_code']
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_metropolitan_municipality_if_requested(result, city, options = nil)
|
98
|
+
return unless options.dig(:with, :metropolitan_municipality_since) || options.dig(:with, :all)
|
99
|
+
|
100
|
+
result[:metropolitan_municipality_since] = city['metropolitan_municipality_since']
|
101
|
+
end
|
102
|
+
|
103
|
+
def unsupported_travel_method(input)
|
104
|
+
I18n.t('errors.unsupported_travel_method', input: input)
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require_relative '../turkish_cities/helpers/decomposer_helper'
|
7
|
+
|
8
|
+
class Postcode
|
9
|
+
include DecomposerHelper
|
10
|
+
|
11
|
+
def find_by_postcode(postcode)
|
12
|
+
check_input_range(postcode, 1010, 81_952)
|
13
|
+
|
14
|
+
city_name = City.new.find_by_id(postcode.to_i / 1000)
|
15
|
+
city_file = create_district_list(city_name)
|
16
|
+
|
17
|
+
city_file.each do |district|
|
18
|
+
district_name = district[0]
|
19
|
+
district[1].each do |subdistrict|
|
20
|
+
return [city_name, district_name, subdistrict[0]] if subdistrict[1]['postcode'] == postcode.to_i
|
21
|
+
end
|
22
|
+
end
|
23
|
+
postcode_not_found_error(postcode)
|
24
|
+
end
|
25
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/turkish_cities.gemspec
CHANGED
@@ -9,9 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ['Semih Arslanoglu']
|
10
10
|
s.email = 'arslanoglusemih93@gmail.com'
|
11
11
|
|
12
|
-
s.date = '2020-04-13'
|
13
12
|
s.summary = 'List and find Turkish cities'
|
14
|
-
s.description = '
|
13
|
+
s.description = 'List and find Turkish cities via name, district name, post code, plate number. Calculate air travel distance between cities and get realistic estimates of travel time'
|
15
14
|
s.homepage = 'https://github.com/sarslanoglu/turkish_cities'
|
16
15
|
s.license = 'MIT'
|
17
16
|
|
@@ -21,10 +20,10 @@ Gem::Specification.new do |s|
|
|
21
20
|
|
22
21
|
s.add_dependency 'i18n', ['>= 0.6.4', '<= 2']
|
23
22
|
|
24
|
-
s.add_development_dependency 'bundler', '~> 2.
|
23
|
+
s.add_development_dependency 'bundler', '~> 2.2.16'
|
25
24
|
s.add_development_dependency 'coveralls', '~> 0.8.23'
|
26
|
-
s.add_development_dependency 'rspec', '~> 3.
|
27
|
-
s.add_development_dependency 'rubocop', '~>
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.10.0'
|
26
|
+
s.add_development_dependency 'rubocop', '~> 1.16.0'
|
28
27
|
|
29
28
|
if s.respond_to?(:metadata)
|
30
29
|
s.metadata['changelog_uri'] = 'https://github.com/sarslanoglu/turkish_cities/blob/master/CHANGELOG.md'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turkish_cities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semih Arslanoglu
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
39
|
+
version: 2.2.16
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 2.
|
46
|
+
version: 2.2.16
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: coveralls
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,35 +64,41 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 3.
|
67
|
+
version: 3.10.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 3.
|
74
|
+
version: 3.10.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rubocop
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 1.16.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
description:
|
90
|
-
number
|
88
|
+
version: 1.16.0
|
89
|
+
description: List and find Turkish cities via name, district name, post code, plate
|
90
|
+
number. Calculate air travel distance between cities and get realistic estimates
|
91
|
+
of travel time
|
91
92
|
email: arslanoglusemih93@gmail.com
|
92
93
|
executables: []
|
93
94
|
extensions: []
|
94
95
|
extra_rdoc_files: []
|
95
96
|
files:
|
97
|
+
- ".codeclimate.yml"
|
98
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
99
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
100
|
+
- ".github/dependabot.yml"
|
101
|
+
- ".github/pull_request_template.md"
|
96
102
|
- ".gitignore"
|
97
103
|
- ".hound.yml"
|
98
104
|
- ".rspec"
|
@@ -105,10 +111,104 @@ files:
|
|
105
111
|
- Gemfile.lock
|
106
112
|
- LICENSE.txt
|
107
113
|
- README.md
|
114
|
+
- config/locales/en.yml
|
115
|
+
- config/locales/tr.yml
|
108
116
|
- lib/turkish_cities.rb
|
109
117
|
- lib/turkish_cities/city.rb
|
110
118
|
- lib/turkish_cities/data/cities.yaml
|
119
|
+
- lib/turkish_cities/data/districts/adana.yaml
|
120
|
+
- lib/turkish_cities/data/districts/adiyaman.yaml
|
121
|
+
- lib/turkish_cities/data/districts/afyon.yaml
|
122
|
+
- lib/turkish_cities/data/districts/agri.yaml
|
123
|
+
- lib/turkish_cities/data/districts/aksaray.yaml
|
124
|
+
- lib/turkish_cities/data/districts/amasya.yaml
|
125
|
+
- lib/turkish_cities/data/districts/ankara.yaml
|
126
|
+
- lib/turkish_cities/data/districts/antalya.yaml
|
127
|
+
- lib/turkish_cities/data/districts/ardahan.yaml
|
128
|
+
- lib/turkish_cities/data/districts/artvin.yaml
|
129
|
+
- lib/turkish_cities/data/districts/aydin.yaml
|
130
|
+
- lib/turkish_cities/data/districts/balikesir.yaml
|
131
|
+
- lib/turkish_cities/data/districts/bartin.yaml
|
132
|
+
- lib/turkish_cities/data/districts/batman.yaml
|
133
|
+
- lib/turkish_cities/data/districts/bayburt.yaml
|
134
|
+
- lib/turkish_cities/data/districts/bilecik.yaml
|
135
|
+
- lib/turkish_cities/data/districts/bingol.yaml
|
136
|
+
- lib/turkish_cities/data/districts/bitlis.yaml
|
137
|
+
- lib/turkish_cities/data/districts/bolu.yaml
|
138
|
+
- lib/turkish_cities/data/districts/burdur.yaml
|
139
|
+
- lib/turkish_cities/data/districts/bursa.yaml
|
140
|
+
- lib/turkish_cities/data/districts/canakkale.yaml
|
141
|
+
- lib/turkish_cities/data/districts/cankiri.yaml
|
142
|
+
- lib/turkish_cities/data/districts/corum.yaml
|
143
|
+
- lib/turkish_cities/data/districts/denizli.yaml
|
144
|
+
- lib/turkish_cities/data/districts/diyarbakir.yaml
|
145
|
+
- lib/turkish_cities/data/districts/duzce.yaml
|
146
|
+
- lib/turkish_cities/data/districts/edirne.yaml
|
147
|
+
- lib/turkish_cities/data/districts/elazig.yaml
|
148
|
+
- lib/turkish_cities/data/districts/erzincan.yaml
|
149
|
+
- lib/turkish_cities/data/districts/erzurum.yaml
|
150
|
+
- lib/turkish_cities/data/districts/eskisehir.yaml
|
151
|
+
- lib/turkish_cities/data/districts/gaziantep.yaml
|
152
|
+
- lib/turkish_cities/data/districts/giresun.yaml
|
153
|
+
- lib/turkish_cities/data/districts/gumushane.yaml
|
154
|
+
- lib/turkish_cities/data/districts/hakkari.yaml
|
155
|
+
- lib/turkish_cities/data/districts/hatay.yaml
|
156
|
+
- lib/turkish_cities/data/districts/igdir.yaml
|
157
|
+
- lib/turkish_cities/data/districts/isparta.yaml
|
158
|
+
- lib/turkish_cities/data/districts/istanbul.yaml
|
159
|
+
- lib/turkish_cities/data/districts/izmir.yaml
|
160
|
+
- lib/turkish_cities/data/districts/kahramanmaras.yaml
|
161
|
+
- lib/turkish_cities/data/districts/karabuk.yaml
|
162
|
+
- lib/turkish_cities/data/districts/karaman.yaml
|
163
|
+
- lib/turkish_cities/data/districts/kars.yaml
|
164
|
+
- lib/turkish_cities/data/districts/kastamonu.yaml
|
165
|
+
- lib/turkish_cities/data/districts/kayseri.yaml
|
166
|
+
- lib/turkish_cities/data/districts/kilis.yaml
|
167
|
+
- lib/turkish_cities/data/districts/kirikkale.yaml
|
168
|
+
- lib/turkish_cities/data/districts/kirklareli.yaml
|
169
|
+
- lib/turkish_cities/data/districts/kirsehir.yaml
|
170
|
+
- lib/turkish_cities/data/districts/kocaeli.yaml
|
171
|
+
- lib/turkish_cities/data/districts/konya.yaml
|
172
|
+
- lib/turkish_cities/data/districts/kutahya.yaml
|
173
|
+
- lib/turkish_cities/data/districts/malatya.yaml
|
174
|
+
- lib/turkish_cities/data/districts/manisa.yaml
|
175
|
+
- lib/turkish_cities/data/districts/mardin.yaml
|
176
|
+
- lib/turkish_cities/data/districts/mersin.yaml
|
177
|
+
- lib/turkish_cities/data/districts/mugla.yaml
|
178
|
+
- lib/turkish_cities/data/districts/mus.yaml
|
179
|
+
- lib/turkish_cities/data/districts/nevsehir.yaml
|
180
|
+
- lib/turkish_cities/data/districts/nigde.yaml
|
181
|
+
- lib/turkish_cities/data/districts/ordu.yaml
|
182
|
+
- lib/turkish_cities/data/districts/osmaniye.yaml
|
183
|
+
- lib/turkish_cities/data/districts/rize.yaml
|
184
|
+
- lib/turkish_cities/data/districts/sakarya.yaml
|
185
|
+
- lib/turkish_cities/data/districts/samsun.yaml
|
186
|
+
- lib/turkish_cities/data/districts/sanliurfa.yaml
|
187
|
+
- lib/turkish_cities/data/districts/siirt.yaml
|
188
|
+
- lib/turkish_cities/data/districts/sinop.yaml
|
189
|
+
- lib/turkish_cities/data/districts/sirnak.yaml
|
190
|
+
- lib/turkish_cities/data/districts/sivas.yaml
|
191
|
+
- lib/turkish_cities/data/districts/tekirdag.yaml
|
192
|
+
- lib/turkish_cities/data/districts/tokat.yaml
|
193
|
+
- lib/turkish_cities/data/districts/trabzon.yaml
|
194
|
+
- lib/turkish_cities/data/districts/tunceli.yaml
|
195
|
+
- lib/turkish_cities/data/districts/usak.yaml
|
196
|
+
- lib/turkish_cities/data/districts/van.yaml
|
197
|
+
- lib/turkish_cities/data/districts/yalova.yaml
|
198
|
+
- lib/turkish_cities/data/districts/yozgat.yaml
|
199
|
+
- lib/turkish_cities/data/districts/zonguldak.yaml
|
200
|
+
- lib/turkish_cities/data/neighborhoods_parser.rb
|
201
|
+
- lib/turkish_cities/distance.rb
|
202
|
+
- lib/turkish_cities/district.rb
|
203
|
+
- lib/turkish_cities/helpers/decomposer_helper.rb
|
204
|
+
- lib/turkish_cities/postcode.rb
|
111
205
|
- lib/turkish_cities/version.rb
|
206
|
+
- public/assets/img/TurkishCities_darkblue-on-yellow_800X800@3x-8.png
|
207
|
+
- public/assets/img/TurkishCities_darkblue-on-yellow_914X343@3x-8.png
|
208
|
+
- public/assets/img/TurkishCities_darkblue-on-yellow_horizontal_914X343@3x-8.png
|
209
|
+
- public/assets/img/TurkishCities_yellow-on-darkblue_800X800@3x-8.png
|
210
|
+
- public/assets/img/TurkishCities_yellow-on-darkblue_914X343@3x-8.png
|
211
|
+
- public/assets/img/TurkishCities_yellow-on-darkblue_horizontal_914X343@3x-8.png
|
112
212
|
- turkish_cities.gemspec
|
113
213
|
homepage: https://github.com/sarslanoglu/turkish_cities
|
114
214
|
licenses:
|
@@ -117,7 +217,7 @@ metadata:
|
|
117
217
|
changelog_uri: https://github.com/sarslanoglu/turkish_cities/blob/master/CHANGELOG.md
|
118
218
|
source_code_uri: https://github.com/sarslanoglu/turkish_cities
|
119
219
|
bug_tracker_uri: https://github.com/sarslanoglu/turkish_cities/issues
|
120
|
-
post_install_message:
|
220
|
+
post_install_message:
|
121
221
|
rdoc_options: []
|
122
222
|
require_paths:
|
123
223
|
- lib
|
@@ -132,8 +232,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
232
|
- !ruby/object:Gem::Version
|
133
233
|
version: '0'
|
134
234
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
235
|
+
rubygems_version: 3.2.17
|
236
|
+
signing_key:
|
137
237
|
specification_version: 4
|
138
238
|
summary: List and find Turkish cities
|
139
239
|
test_files: []
|