turkish_cities 0.3.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +20 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +22 -0
- data/Gemfile.lock +21 -21
- data/README.md +143 -13
- data/config/locales/en.yml +19 -0
- data/config/locales/tr.yml +19 -0
- data/lib/turkish_cities/city.rb +1 -3
- data/lib/turkish_cities/data/cities.yaml +267 -0
- data/lib/turkish_cities/data/districts/adana.yaml +1 -1
- data/lib/turkish_cities/data/districts/adiyaman.yaml +184 -176
- data/lib/turkish_cities/data/districts/afyon.yaml +295 -189
- data/lib/turkish_cities/data/districts/agri.yaml +28 -28
- data/lib/turkish_cities/data/districts/aksaray.yaml +90 -61
- data/lib/turkish_cities/data/districts/amasya.yaml +17 -6
- data/lib/turkish_cities/data/districts/ankara.yaml +22 -22
- data/lib/turkish_cities/data/districts/antalya.yaml +3 -3
- data/lib/turkish_cities/data/districts/ardahan.yaml +10 -7
- data/lib/turkish_cities/data/districts/artvin.yaml +0 -60
- data/lib/turkish_cities/data/districts/bartin.yaml +23 -19
- data/lib/turkish_cities/data/districts/batman.yaml +45 -28
- data/lib/turkish_cities/data/districts/bayburt.yaml +12 -6
- data/lib/turkish_cities/data/districts/bilecik.yaml +18 -14
- data/lib/turkish_cities/data/districts/bingol.yaml +29 -35
- data/lib/turkish_cities/data/districts/bitlis.yaml +56 -43
- data/lib/turkish_cities/data/districts/bolu.yaml +34 -58
- data/lib/turkish_cities/data/districts/burdur.yaml +22 -16
- data/lib/turkish_cities/data/districts/bursa.yaml +3 -2
- data/lib/turkish_cities/data/districts/canakkale.yaml +46 -47
- data/lib/turkish_cities/data/districts/cankiri.yaml +23 -18
- data/lib/turkish_cities/data/districts/corum.yaml +25 -15
- data/lib/turkish_cities/data/districts/denizli.yaml +1 -1
- data/lib/turkish_cities/data/districts/diyarbakir.yaml +6 -6
- data/lib/turkish_cities/data/districts/duzce.yaml +83 -74
- data/lib/turkish_cities/data/districts/edirne.yaml +37 -23
- data/lib/turkish_cities/data/districts/elazig.yaml +74 -54
- data/lib/turkish_cities/data/districts/erzincan.yaml +47 -38
- data/lib/turkish_cities/data/districts/erzurum.yaml +1 -1
- data/lib/turkish_cities/data/districts/giresun.yaml +125 -57
- data/lib/turkish_cities/data/districts/gumushane.yaml +61 -81
- data/lib/turkish_cities/data/districts/hakkari.yaml +22 -15
- data/lib/turkish_cities/data/districts/hatay.yaml +1 -1
- data/lib/turkish_cities/data/districts/igdir.yaml +20 -11
- data/lib/turkish_cities/data/districts/isparta.yaml +67 -40
- data/lib/turkish_cities/data/districts/istanbul.yaml +12 -12
- data/lib/turkish_cities/data/districts/izmir.yaml +12 -12
- data/lib/turkish_cities/data/districts/kahramanmaras.yaml +3 -2
- data/lib/turkish_cities/data/districts/karabuk.yaml +15 -28
- data/lib/turkish_cities/data/districts/karaman.yaml +36 -31
- data/lib/turkish_cities/data/districts/kars.yaml +5 -4
- data/lib/turkish_cities/data/districts/kastamonu.yaml +3 -29
- data/lib/turkish_cities/data/districts/kayseri.yaml +8 -8
- data/lib/turkish_cities/data/districts/kilis.yaml +3 -2
- data/lib/turkish_cities/data/districts/kirikkale.yaml +17 -13
- data/lib/turkish_cities/data/districts/kirklareli.yaml +63 -45
- data/lib/turkish_cities/data/districts/kirsehir.yaml +25 -16
- data/lib/turkish_cities/data/districts/kocaeli.yaml +1 -1
- data/lib/turkish_cities/data/districts/konya.yaml +7 -8
- data/lib/turkish_cities/data/districts/kutahya.yaml +104 -72
- data/lib/turkish_cities/data/districts/malatya.yaml +1 -1
- data/lib/turkish_cities/data/districts/manisa.yaml +2 -2
- data/lib/turkish_cities/data/districts/mersin.yaml +4 -4
- data/lib/turkish_cities/data/districts/mus.yaml +118 -74
- data/lib/turkish_cities/data/districts/nevsehir.yaml +51 -43
- data/lib/turkish_cities/data/districts/nigde.yaml +135 -76
- data/lib/turkish_cities/data/districts/ordu.yaml +3 -3
- data/lib/turkish_cities/data/districts/osmaniye.yaml +53 -32
- data/lib/turkish_cities/data/districts/rize.yaml +68 -46
- data/lib/turkish_cities/data/districts/sakarya.yaml +2 -2
- data/lib/turkish_cities/data/districts/samsun.yaml +3 -3
- data/lib/turkish_cities/data/districts/sanliurfa.yaml +7 -7
- data/lib/turkish_cities/data/districts/siirt.yaml +27 -13
- data/lib/turkish_cities/data/districts/sinop.yaml +1 -5
- data/lib/turkish_cities/data/districts/sirnak.yaml +78 -40
- data/lib/turkish_cities/data/districts/sivas.yaml +49 -52
- data/lib/turkish_cities/data/districts/tekirdag.yaml +7 -2
- data/lib/turkish_cities/data/districts/tokat.yaml +201 -138
- data/lib/turkish_cities/data/districts/trabzon.yaml +1 -0
- data/lib/turkish_cities/data/districts/tunceli.yaml +13 -9
- data/lib/turkish_cities/data/districts/usak.yaml +40 -24
- data/lib/turkish_cities/data/districts/van.yaml +6 -4
- data/lib/turkish_cities/data/districts/yalova.yaml +45 -21
- data/lib/turkish_cities/data/districts/yozgat.yaml +147 -80
- data/lib/turkish_cities/data/districts/zonguldak.yaml +127 -90
- data/lib/turkish_cities/data/neighborhoods_parser.rb +4 -4
- data/lib/turkish_cities/distance.rb +33 -3
- data/lib/turkish_cities/helpers/decomposer_helper.rb +21 -7
- data/lib/turkish_cities/population.rb +66 -0
- data/lib/turkish_cities/version.rb +1 -1
- data/lib/turkish_cities.rb +22 -2
- data/turkish_cities.gemspec +2 -3
- metadata +11 -8
- data/.travis.yml +0 -21
@@ -4,15 +4,23 @@ module DecomposerHelper
|
|
4
4
|
def check_input_range(input, min, max)
|
5
5
|
return if input.to_i.between?(min, max)
|
6
6
|
|
7
|
-
raise RangeError,
|
7
|
+
raise RangeError, I18n.t('errors.outside_bounds', input: input, min: min, max: max)
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_population_range(input, min, max)
|
11
|
+
input.to_i.between?(min, max)
|
8
12
|
end
|
9
13
|
|
10
14
|
def city_not_found_error(input)
|
11
|
-
|
15
|
+
I18n.t('errors.city_not_found_error', input: input)
|
16
|
+
end
|
17
|
+
|
18
|
+
def city_population_not_found_error
|
19
|
+
I18n.t('errors.city_population_not_found_error')
|
12
20
|
end
|
13
21
|
|
14
22
|
def cities_not_found_error(first, second)
|
15
|
-
|
23
|
+
I18n.t('errors.cities_not_found_error', first: first, second: second)
|
16
24
|
end
|
17
25
|
|
18
26
|
def convert_chars(string)
|
@@ -35,11 +43,11 @@ module DecomposerHelper
|
|
35
43
|
end
|
36
44
|
|
37
45
|
def district_not_found_error(district_input, city_input)
|
38
|
-
|
46
|
+
I18n.t('errors.district_not_found_error', district_input: district_input, city_input: city_input)
|
39
47
|
end
|
40
48
|
|
41
49
|
def postcode_not_found_error(postcode_input)
|
42
|
-
|
50
|
+
I18n.t('errors.postcode_not_found_error', postcode_input: postcode_input)
|
43
51
|
end
|
44
52
|
|
45
53
|
def prepare_city_list(city_list, options)
|
@@ -64,6 +72,7 @@ module DecomposerHelper
|
|
64
72
|
|
65
73
|
def sort_alphabetically(list, options = nil)
|
66
74
|
turkish_alphabet = ' -0123456789abcçdefgğhıijklmnoöprsştuüvyz'
|
75
|
+
|
67
76
|
list.sort_by do |item|
|
68
77
|
item_to_sort = if options.nil? || options[:with].nil?
|
69
78
|
item
|
@@ -75,7 +84,8 @@ module DecomposerHelper
|
|
75
84
|
end
|
76
85
|
|
77
86
|
def subdistrict_not_found_error(subdistrict_input, district_input, city_input)
|
78
|
-
|
87
|
+
I18n.t('errors.subdistrict_not_found_error', subdistrict_input: subdistrict_input, district_input: district_input,
|
88
|
+
city_input: city_input)
|
79
89
|
end
|
80
90
|
|
81
91
|
private
|
@@ -98,7 +108,11 @@ module DecomposerHelper
|
|
98
108
|
result[:metropolitan_municipality_since] = city['metropolitan_municipality_since']
|
99
109
|
end
|
100
110
|
|
111
|
+
def unsupported_population_type(input)
|
112
|
+
I18n.t('errors.unsupported_population_type', input: input)
|
113
|
+
end
|
114
|
+
|
101
115
|
def unsupported_travel_method(input)
|
102
|
-
|
116
|
+
I18n.t('errors.unsupported_travel_method', input: input)
|
103
117
|
end
|
104
118
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'i18n'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require_relative '../turkish_cities/helpers/decomposer_helper'
|
7
|
+
|
8
|
+
class Population
|
9
|
+
include DecomposerHelper
|
10
|
+
|
11
|
+
file_path = File.join(File.dirname(__FILE__), 'data/cities.yaml')
|
12
|
+
CITY_LIST = YAML.load_file(file_path)
|
13
|
+
|
14
|
+
def find_by_population(type, population_one, population_two)
|
15
|
+
return [] unless check_population_range(population_one, 83_645, 15_840_900)
|
16
|
+
|
17
|
+
return [] if !population_two.nil? && !check_population_range(population_two, 83_645, 15_840_900)
|
18
|
+
|
19
|
+
result = find_population(type, population_one, population_two)
|
20
|
+
|
21
|
+
result.length.positive? ? result : city_population_not_found_error
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def find_population(type, population_one, population_two)
|
27
|
+
city_list = CITY_LIST
|
28
|
+
|
29
|
+
case type
|
30
|
+
when 'exact'
|
31
|
+
exact_population(city_list, population_one)
|
32
|
+
when 'below'
|
33
|
+
below_population(city_list, population_one)
|
34
|
+
when 'above'
|
35
|
+
above_population(city_list, population_one)
|
36
|
+
when 'between'
|
37
|
+
between_population(city_list, population_one, population_two)
|
38
|
+
else
|
39
|
+
unsupported_population_type(type)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def exact_population(city_list, population)
|
44
|
+
city_list.map { |city| city['name'] if city['population'] == population }.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def below_population(city_list, population)
|
48
|
+
city_list.map { |city| city['name'] if city['population'] < population }.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def above_population(city_list, population)
|
52
|
+
city_list.map { |city| city['name'] if city['population'] > population }.compact
|
53
|
+
end
|
54
|
+
|
55
|
+
def between_population(city_list, population_one, population_two)
|
56
|
+
if population_one > population_two
|
57
|
+
bigger = population_one
|
58
|
+
smaller = population_two
|
59
|
+
else
|
60
|
+
smaller = population_one
|
61
|
+
bigger = population_two
|
62
|
+
end
|
63
|
+
|
64
|
+
city_list.map { |city| city['name'] if city['population'] > smaller && city['population'] < bigger }.compact
|
65
|
+
end
|
66
|
+
end
|
data/lib/turkish_cities.rb
CHANGED
@@ -3,10 +3,26 @@
|
|
3
3
|
require_relative '../lib/turkish_cities/city'
|
4
4
|
require_relative '../lib/turkish_cities/distance'
|
5
5
|
require_relative '../lib/turkish_cities/district'
|
6
|
+
require_relative '../lib/turkish_cities/population'
|
6
7
|
require_relative '../lib/turkish_cities/postcode'
|
7
8
|
require_relative '../lib/turkish_cities/version'
|
8
9
|
|
10
|
+
require 'i18n'
|
11
|
+
|
12
|
+
I18n.load_path << Dir["#{File.expand_path('config/locales')}/*.yml"]
|
13
|
+
|
9
14
|
class TurkishCities
|
15
|
+
PLATE_NUMBER = 'plate_number'
|
16
|
+
PHONE_CODE = 'phone_code'
|
17
|
+
|
18
|
+
def self.change_locale(language_code)
|
19
|
+
if %w[en tr].include?(language_code)
|
20
|
+
I18n.locale = language_code.to_sym
|
21
|
+
return I18n.t('language.success')
|
22
|
+
end
|
23
|
+
I18n.t('language.errors.unsupported_language_code')
|
24
|
+
end
|
25
|
+
|
10
26
|
def self.find_name_by_plate_number(plate_number)
|
11
27
|
City.new.find_by_id(plate_number)
|
12
28
|
end
|
@@ -16,11 +32,11 @@ class TurkishCities
|
|
16
32
|
end
|
17
33
|
|
18
34
|
def self.find_plate_number_by_name(city_name)
|
19
|
-
City.new.find_by_name(city_name,
|
35
|
+
City.new.find_by_name(city_name, self::PLATE_NUMBER)
|
20
36
|
end
|
21
37
|
|
22
38
|
def self.find_phone_code_by_name(city_name)
|
23
|
-
City.new.find_by_name(city_name,
|
39
|
+
City.new.find_by_name(city_name, self::PHONE_CODE)
|
24
40
|
end
|
25
41
|
|
26
42
|
def self.list_cities(options = {})
|
@@ -43,6 +59,10 @@ class TurkishCities
|
|
43
59
|
District.new(city_name, district_name).neighborhoods(subdistrict_name)
|
44
60
|
end
|
45
61
|
|
62
|
+
def self.find_by_population(type, population_one, population_two = nil)
|
63
|
+
Population.new.find_by_population(type, population_one, population_two)
|
64
|
+
end
|
65
|
+
|
46
66
|
def self.find_by_postcode(postcode)
|
47
67
|
Postcode.new.find_by_postcode(postcode)
|
48
68
|
end
|
data/turkish_cities.gemspec
CHANGED
@@ -9,7 +9,6 @@ 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
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'
|
@@ -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
25
|
s.add_development_dependency 'rspec', '~> 3.10.0'
|
27
|
-
s.add_development_dependency 'rubocop', '~> 1.
|
26
|
+
s.add_development_dependency 'rubocop', '~> 1.25.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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semih Arslanoglu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-26 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
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.
|
81
|
+
version: 1.25.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: 1.
|
88
|
+
version: 1.25.0
|
89
89
|
description: List and find Turkish cities via name, district name, post code, plate
|
90
90
|
number. Calculate air travel distance between cities and get realistic estimates
|
91
91
|
of travel time
|
@@ -97,12 +97,12 @@ files:
|
|
97
97
|
- ".codeclimate.yml"
|
98
98
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
99
99
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
100
|
+
- ".github/dependabot.yml"
|
100
101
|
- ".github/pull_request_template.md"
|
101
102
|
- ".gitignore"
|
102
103
|
- ".hound.yml"
|
103
104
|
- ".rspec"
|
104
105
|
- ".rubocop.yml"
|
105
|
-
- ".travis.yml"
|
106
106
|
- CHANGELOG.md
|
107
107
|
- CODE_OF_CONDUCT.md
|
108
108
|
- CONTRIBUTING.md
|
@@ -110,6 +110,8 @@ files:
|
|
110
110
|
- Gemfile.lock
|
111
111
|
- LICENSE.txt
|
112
112
|
- README.md
|
113
|
+
- config/locales/en.yml
|
114
|
+
- config/locales/tr.yml
|
113
115
|
- lib/turkish_cities.rb
|
114
116
|
- lib/turkish_cities/city.rb
|
115
117
|
- lib/turkish_cities/data/cities.yaml
|
@@ -198,6 +200,7 @@ files:
|
|
198
200
|
- lib/turkish_cities/distance.rb
|
199
201
|
- lib/turkish_cities/district.rb
|
200
202
|
- lib/turkish_cities/helpers/decomposer_helper.rb
|
203
|
+
- lib/turkish_cities/population.rb
|
201
204
|
- lib/turkish_cities/postcode.rb
|
202
205
|
- lib/turkish_cities/version.rb
|
203
206
|
- public/assets/img/TurkishCities_darkblue-on-yellow_800X800@3x-8.png
|
@@ -229,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
232
|
- !ruby/object:Gem::Version
|
230
233
|
version: '0'
|
231
234
|
requirements: []
|
232
|
-
rubygems_version: 3.
|
235
|
+
rubygems_version: 3.2.17
|
233
236
|
signing_key:
|
234
237
|
specification_version: 4
|
235
238
|
summary: List and find Turkish cities
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
env:
|
2
|
-
global:
|
3
|
-
- CC_TEST_REPORTER_ID=23062197f289fd0ae7601ae06c2dd4a0af4e16c436f2428b99ab4b64a7e4a587
|
4
|
-
language: ruby
|
5
|
-
dist: trusty
|
6
|
-
rvm:
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
9
|
-
- 2.7
|
10
|
-
before_install:
|
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
|
16
|
-
script: bundle exec rspec spec
|
17
|
-
after_script:
|
18
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
19
|
-
notifications:
|
20
|
-
email:
|
21
|
-
- arslanoglusemih93@gmail.com
|