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
@@ -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, "Given value [#{input}] is outside bounds of #{min} to #{max}."
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
- "Couldn't find city name with '#{input}'"
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
- "Couldn't find cities combination with '#{first}/#{second}'"
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
- "Couldn't find district name with '#{district_input}' of '#{city_input}'"
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
- "Couldn't find any subdistrict with postcode '#{postcode_input}'"
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
- "Couldn't find subdistrict with '#{subdistrict_input}' of '#{district_input}'/'#{city_input}'"
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
- "Travel method '#{input}' is unsupported"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TurkishCities
4
- VERSION = '0.4.0'
4
+ VERSION = '0.6.1'
5
5
  end
@@ -3,10 +3,27 @@
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 << "#{File.expand_path('config/locales')}/en.yml"
13
+ I18n.load_path << "#{File.expand_path('config/locales')}/tr.yml"
14
+
9
15
  class TurkishCities
16
+ PLATE_NUMBER = 'plate_number'
17
+ PHONE_CODE = 'phone_code'
18
+
19
+ def self.change_locale(language_code)
20
+ if %w[en tr].include?(language_code)
21
+ I18n.locale = language_code.to_sym
22
+ return I18n.t('language.success')
23
+ end
24
+ I18n.t('language.errors.unsupported_language_code')
25
+ end
26
+
10
27
  def self.find_name_by_plate_number(plate_number)
11
28
  City.new.find_by_id(plate_number)
12
29
  end
@@ -16,11 +33,11 @@ class TurkishCities
16
33
  end
17
34
 
18
35
  def self.find_plate_number_by_name(city_name)
19
- City.new.find_by_name(city_name, 'plate_number')
36
+ City.new.find_by_name(city_name, self::PLATE_NUMBER)
20
37
  end
21
38
 
22
39
  def self.find_phone_code_by_name(city_name)
23
- City.new.find_by_name(city_name, 'phone_code')
40
+ City.new.find_by_name(city_name, self::PHONE_CODE)
24
41
  end
25
42
 
26
43
  def self.list_cities(options = {})
@@ -43,6 +60,10 @@ class TurkishCities
43
60
  District.new(city_name, district_name).neighborhoods(subdistrict_name)
44
61
  end
45
62
 
63
+ def self.find_by_population(type, population_one, population_two = nil)
64
+ Population.new.find_by_population(type, population_one, population_two)
65
+ end
66
+
46
67
  def self.find_by_postcode(postcode)
47
68
  Postcode.new.find_by_postcode(postcode)
48
69
  end
@@ -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'
@@ -22,9 +21,10 @@ Gem::Specification.new do |s|
22
21
  s.add_dependency 'i18n', ['>= 0.6.4', '<= 2']
23
22
 
24
23
  s.add_development_dependency 'bundler', '~> 2.2.16'
25
- s.add_development_dependency 'coveralls', '~> 0.8.23'
26
- s.add_development_dependency 'rspec', '~> 3.10.0'
27
- s.add_development_dependency 'rubocop', '~> 1.3.1'
24
+ s.add_development_dependency 'codecov', '~> 0.6.0'
25
+ s.add_development_dependency 'rake', '~> 13.0.6'
26
+ s.add_development_dependency 'rspec', '~> 3.11.0'
27
+ s.add_development_dependency 'rubocop', '~> 1.27.0'
28
28
 
29
29
  if s.respond_to?(:metadata)
30
30
  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.0
4
+ version: 0.6.1
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: 2020-04-13 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -45,47 +45,61 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.2.16
47
47
  - !ruby/object:Gem::Dependency
48
- name: coveralls
48
+ name: codecov
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.8.23
53
+ version: 0.6.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 0.8.23
60
+ version: 0.6.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 13.0.6
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 13.0.6
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rspec
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - "~>"
66
80
  - !ruby/object:Gem::Version
67
- version: 3.10.0
81
+ version: 3.11.0
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: 3.10.0
88
+ version: 3.11.0
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rubocop
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: 1.3.1
95
+ version: 1.27.0
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
100
  - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: 1.3.1
102
+ version: 1.27.0
89
103
  description: List and find Turkish cities via name, district name, post code, plate
90
104
  number. Calculate air travel distance between cities and get realistic estimates
91
105
  of travel time
@@ -94,15 +108,17 @@ executables: []
94
108
  extensions: []
95
109
  extra_rdoc_files: []
96
110
  files:
111
+ - ".circleci/config.yml"
97
112
  - ".codeclimate.yml"
98
113
  - ".github/ISSUE_TEMPLATE/bug_report.md"
99
114
  - ".github/ISSUE_TEMPLATE/feature_request.md"
115
+ - ".github/dependabot.yml"
100
116
  - ".github/pull_request_template.md"
117
+ - ".github/workflows/ruby.yml"
101
118
  - ".gitignore"
102
119
  - ".hound.yml"
103
120
  - ".rspec"
104
121
  - ".rubocop.yml"
105
- - ".travis.yml"
106
122
  - CHANGELOG.md
107
123
  - CODE_OF_CONDUCT.md
108
124
  - CONTRIBUTING.md
@@ -110,6 +126,9 @@ files:
110
126
  - Gemfile.lock
111
127
  - LICENSE.txt
112
128
  - README.md
129
+ - Rakefile
130
+ - config/locales/en.yml
131
+ - config/locales/tr.yml
113
132
  - lib/turkish_cities.rb
114
133
  - lib/turkish_cities/city.rb
115
134
  - lib/turkish_cities/data/cities.yaml
@@ -198,6 +217,7 @@ files:
198
217
  - lib/turkish_cities/distance.rb
199
218
  - lib/turkish_cities/district.rb
200
219
  - lib/turkish_cities/helpers/decomposer_helper.rb
220
+ - lib/turkish_cities/population.rb
201
221
  - lib/turkish_cities/postcode.rb
202
222
  - lib/turkish_cities/version.rb
203
223
  - public/assets/img/TurkishCities_darkblue-on-yellow_800X800@3x-8.png
@@ -214,7 +234,7 @@ metadata:
214
234
  changelog_uri: https://github.com/sarslanoglu/turkish_cities/blob/master/CHANGELOG.md
215
235
  source_code_uri: https://github.com/sarslanoglu/turkish_cities
216
236
  bug_tracker_uri: https://github.com/sarslanoglu/turkish_cities/issues
217
- post_install_message:
237
+ post_install_message:
218
238
  rdoc_options: []
219
239
  require_paths:
220
240
  - lib
@@ -229,8 +249,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
249
  - !ruby/object:Gem::Version
230
250
  version: '0'
231
251
  requirements: []
232
- rubygems_version: 3.0.3
233
- signing_key:
252
+ rubygems_version: 3.2.3
253
+ signing_key:
234
254
  specification_version: 4
235
255
  summary: List and find Turkish cities
236
256
  test_files: []
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