turkish_cities 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14e3cb00362c30c66924e86fb009a79dd9ef16b086166ec0eb1be136653e7cc7
4
- data.tar.gz: a1b61fbd9f3319d5973acf35b029bb315460b83d0d8ebcfb15d30405eab0e6cb
3
+ metadata.gz: bae35e49b4b510ec357661984e1fe58147fb814c0d3fa05884b267d1dc73c3e8
4
+ data.tar.gz: e0107fac60f4c94f319a3a7abe9dc0a3d2dcde7be97636ae289755d64a017efa
5
5
  SHA512:
6
- metadata.gz: 4a0d5834616ddfe7cf080efd3182d599f7901a1d139f831aa85a7ff81d66498bb2ad8a2e118e9c935fadf679cb86f249ae6210f986a38408a1d21c8e5e313b17
7
- data.tar.gz: ea17bd392eb05c6bfa1413cc0754d749a2dc53874d5944bc37603c98cf2f65c9de9c9c9a68d208bcbde738c73f59e9b09740f23d5899526ff7a8080e15732197
6
+ metadata.gz: dcbef3333549bcf28f20597ae6b43948fc6555c1e407baaa358bc2da1f13b0a60afbd86e1211b2dfccbe9fd1ca7690bbedd1499db47d553b3d59a44d26b8d995
7
+ data.tar.gz: bd4196417c877097d240d7d44005debf81d0171c20b1b290cbdbe5b81053dc154dbacf092a20413cda142cecfb83d6eaa8c0f52391d3311961b6b83e0f20b6e3
@@ -0,0 +1,20 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: monthly
7
+ time: "09:00"
8
+ open-pull-requests-limit: 10
9
+ ignore:
10
+ - dependency-name: rubocop
11
+ versions:
12
+ - 1.8.1
13
+ - 1.9.1
14
+ - dependency-name: bundler
15
+ versions:
16
+ - 2.2.6
17
+ - 2.2.7
18
+ - dependency-name: i18n
19
+ versions:
20
+ - 1.8.7
data/.hound.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  rubocop:
2
- version: 0.83.0
2
+ version: 1.5.2
3
3
  config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -4,12 +4,13 @@ AllCops:
4
4
  - 'Gemfile'
5
5
  - 'turkish_cities.gemspec'
6
6
  NewCops: enable
7
+ SuggestExtensions: false
7
8
  Layout/LineLength:
8
9
  Max: 120
9
10
  Metrics/AbcSize:
10
11
  Max: 20
11
12
  Metrics/BlockLength:
12
- ExcludedMethods: ['describe', 'context']
13
+ IgnoredMethods: ['describe', 'context']
13
14
  Metrics/MethodLength:
14
15
  Max: 15
15
16
  Style/Documentation:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 (2021-06-06)
4
+
5
+ ### New features
6
+
7
+ * [#68](https://github.com/sarslanoglu/turkish_cities/issues/68): Add localization for all method responses and errors
8
+
3
9
  ## 0.4.0 (2021-04-25)
4
10
 
5
11
  ### New features
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turkish_cities (0.4.0)
4
+ turkish_cities (0.5.0)
5
5
  i18n (>= 0.6.4, <= 2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ast (2.4.1)
11
- concurrent-ruby (1.1.6)
10
+ ast (2.4.2)
11
+ concurrent-ruby (1.1.8)
12
12
  coveralls (0.8.23)
13
13
  json (>= 1.8, < 3)
14
14
  simplecov (~> 0.16.1)
@@ -17,15 +17,15 @@ GEM
17
17
  tins (~> 1.6)
18
18
  diff-lcs (1.4.4)
19
19
  docile (1.3.2)
20
- i18n (1.8.5)
20
+ i18n (1.8.10)
21
21
  concurrent-ruby (~> 1.0)
22
22
  json (2.3.0)
23
- parallel (1.20.0)
24
- parser (2.7.2.0)
23
+ parallel (1.20.1)
24
+ parser (3.0.1.1)
25
25
  ast (~> 2.4.1)
26
26
  rainbow (3.0.0)
27
- regexp_parser (1.8.2)
28
- rexml (3.2.4)
27
+ regexp_parser (2.1.1)
28
+ rexml (3.2.5)
29
29
  rspec (3.10.0)
30
30
  rspec-core (~> 3.10.0)
31
31
  rspec-expectations (~> 3.10.0)
@@ -39,18 +39,18 @@ GEM
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
40
  rspec-support (~> 3.10.0)
41
41
  rspec-support (3.10.0)
42
- rubocop (1.3.1)
42
+ rubocop (1.16.0)
43
43
  parallel (~> 1.10)
44
- parser (>= 2.7.1.5)
44
+ parser (>= 3.0.0.0)
45
45
  rainbow (>= 2.2.2, < 4.0)
46
- regexp_parser (>= 1.8)
46
+ regexp_parser (>= 1.8, < 3.0)
47
47
  rexml
48
- rubocop-ast (>= 1.1.1)
48
+ rubocop-ast (>= 1.7.0, < 2.0)
49
49
  ruby-progressbar (~> 1.7)
50
- unicode-display_width (>= 1.4.0, < 2.0)
51
- rubocop-ast (1.1.1)
52
- parser (>= 2.7.1.5)
53
- ruby-progressbar (1.10.1)
50
+ unicode-display_width (>= 1.4.0, < 3.0)
51
+ rubocop-ast (1.7.0)
52
+ parser (>= 3.0.1.1)
53
+ ruby-progressbar (1.11.0)
54
54
  simplecov (0.16.1)
55
55
  docile (~> 1.1)
56
56
  json (>= 1.8, < 3)
@@ -62,7 +62,7 @@ GEM
62
62
  thor (1.0.1)
63
63
  tins (1.25.0)
64
64
  sync
65
- unicode-display_width (1.7.0)
65
+ unicode-display_width (2.0.0)
66
66
 
67
67
  PLATFORMS
68
68
  ruby
@@ -71,7 +71,7 @@ DEPENDENCIES
71
71
  bundler (~> 2.2.16)
72
72
  coveralls (~> 0.8.23)
73
73
  rspec (~> 3.10.0)
74
- rubocop (~> 1.3.1)
74
+ rubocop (~> 1.16.0)
75
75
  turkish_cities!
76
76
 
77
77
  BUNDLED WITH
data/README.md CHANGED
@@ -20,6 +20,7 @@ https://rubygems.org/gems/turkish_cities
20
20
 
21
21
  ## Table of Contents
22
22
  * [Installation](#installation)
23
+ * [Localization](#localization)
23
24
  * [Documentation](#documentation)
24
25
  * [Finding city name by plate number](#finding-city-name-by-plate-number)
25
26
  * [Finding city name by phone code](#finding-city-name-by-phone-code)
@@ -63,6 +64,24 @@ and run
63
64
  $ bundle
64
65
  ```
65
66
 
67
+ ## Localization
68
+
69
+ Currently gem supports two different languages, Turkish and English. English is default, if no action taken.
70
+
71
+ Language can be easily changed by ```change_locale``` method. Valid parameters are 'tr' for Turkish and 'en' for English.
72
+
73
+ ```rb
74
+ TurkishCities.change_locale('tr') # => "Dil Türkçe olarak ayarlandı."
75
+ ```
76
+
77
+ After changing language all errors and result sets will be in desired language
78
+
79
+ ```rb
80
+ TurkishCities.list_districts('Eskişehirrr') # => "'Eskişehirrr' ile bir şehir bulunamadı"
81
+ TurkishCities.distance_between('kirsehir', 'Ordu', 'land')
82
+ # => [533, "Kırşehir ile Ordu arasındaki karayolu mesafesi 533 km"]
83
+ ```
84
+
66
85
  ## Documentation
67
86
 
68
87
  With using irb just require gem and start using
@@ -319,9 +338,9 @@ https://www.kgm.gov.tr/SiteCollectionDocuments/KGMdocuments/Root/Uzakliklar/ilme
319
338
 
320
339
  | Ruby Version | Supported |
321
340
  | ------------ | ------------------ |
322
- | 2.7.1 | :white_check_mark: |
323
- | 2.6.6 | :white_check_mark: |
324
- | 2.5.8 | :white_check_mark: |
341
+ | 2.7.x | :white_check_mark: |
342
+ | 2.6.x | :white_check_mark: |
343
+ | 2.5.x | :white_check_mark: |
325
344
  | < 2.5.1 | :x: |
326
345
 
327
346
  - TurkishCities heavily depends on ```:turkic``` case mapping support of Ruby string downcase method. Below Ruby version 2.5.1 some functions will run buggy/false or even won't run at all.
@@ -329,7 +348,6 @@ https://www.kgm.gov.tr/SiteCollectionDocuments/KGMdocuments/Root/Uzakliklar/ilme
329
348
  ## Roadmap
330
349
 
331
350
  - Add missing sea travel method
332
- - Add localization to gem
333
351
  - Refactor tests (separate test suites with more edge case tests)
334
352
 
335
353
  ## Contributing
@@ -0,0 +1,17 @@
1
+ en:
2
+ description_text:
3
+ air_travel: "Air travel distance between %{first_city} and %{second_city} is %{distance} km. Estimated air travel would take %{duration} minutes"
4
+ land_travel: "Land travel distance between %{first_city} and %{second_city} is %{distance} km"
5
+ errors:
6
+ cities_not_found_error: "Couldn't find cities combination with '%{first}/%{second}'"
7
+ city_not_found_error: "Couldn't find city name with '%{input}'"
8
+ district_not_found_error: "Couldn't find district name with '%{district_input}' of '%{city_input}'"
9
+ not_even_input: "Given value [%{input}] must be an even number"
10
+ outside_bounds: "Given value [%{input}] is outside bounds of %{min} to %{max}"
11
+ postcode_not_found_error: "Couldn't find any subdistrict with postcode '%{postcode_input}'"
12
+ subdistrict_not_found_error: "Couldn't find subdistrict with '%{subdistrict_input}' of '%{district_input}'/'%{city_input}'"
13
+ unsupported_travel_method: "Travel method '%{input}' is unsupported"
14
+ language:
15
+ errors:
16
+ unsupported_language_code: "Unsupported language code. Please use 'tr' for Turkish, 'en' for English"
17
+ success: "Language set to English"
@@ -0,0 +1,17 @@
1
+ tr:
2
+ description_text:
3
+ air_travel: "%{first_city} ile %{second_city} arasındaki havayolu mesafesi %{distance} km. Tahmini uçuş süresi %{duration} dakikadır"
4
+ land_travel: "%{first_city} ile %{second_city} arasındaki karayolu mesafesi %{distance} km"
5
+ errors:
6
+ cities_not_found_error: "'%{first}/%{second}' ile şehir kombinasyonu bulunamadı"
7
+ city_not_found_error: "'%{input}' ile bir şehir bulunamadı"
8
+ district_not_found_error: "'%{city_input}' şehrine ait '%{district_input}' ilçesi ile bir kayıt bulunamadı"
9
+ not_even_input: "Girilen değer [%{input}] çift sayı olmalı"
10
+ outside_bounds: "Girilen değer [%{input}] %{min} ile %{max} değerleri dışında"
11
+ postcode_not_found_error: "'%{postcode_input}' posta kodu ile kayıt bulunamadı"
12
+ subdistrict_not_found_error: "'%{subdistrict_input}' ile '%{district_input}'/'%{city_input}' ait bir kayıt bulunamdı"
13
+ unsupported_travel_method: "'%{input}' yolculuk methodu desteklenmiyor"
14
+ language:
15
+ errors:
16
+ unsupported_language_code: "Desteklenmeyen dil kodu. Lütfen Türkçe için 'tr', İngilizce için 'en' kullanınız"
17
+ success: "Dil Türkçe olarak ayarlandı"
@@ -6,7 +6,22 @@ require_relative '../lib/turkish_cities/district'
6
6
  require_relative '../lib/turkish_cities/postcode'
7
7
  require_relative '../lib/turkish_cities/version'
8
8
 
9
+ require 'i18n'
10
+
11
+ I18n.load_path << Dir["#{File.expand_path('config/locales')}/*.yml"]
12
+
9
13
  class TurkishCities
14
+ PLATE_NUMBER = 'plate_number'
15
+ PHONE_CODE = 'phone_code'
16
+
17
+ def self.change_locale(language_code)
18
+ if %w[en tr].include?(language_code)
19
+ I18n.locale = language_code.to_sym
20
+ return I18n.t('language.success')
21
+ end
22
+ I18n.t('language.errors.unsupported_language_code')
23
+ end
24
+
10
25
  def self.find_name_by_plate_number(plate_number)
11
26
  City.new.find_by_id(plate_number)
12
27
  end
@@ -16,11 +31,11 @@ class TurkishCities
16
31
  end
17
32
 
18
33
  def self.find_plate_number_by_name(city_name)
19
- City.new.find_by_name(city_name, 'plate_number')
34
+ City.new.find_by_name(city_name, self::PLATE_NUMBER)
20
35
  end
21
36
 
22
37
  def self.find_phone_code_by_name(city_name)
23
- City.new.find_by_name(city_name, 'phone_code')
38
+ City.new.find_by_name(city_name, self::PHONE_CODE)
24
39
  end
25
40
 
26
41
  def self.list_cities(options = {})
@@ -8,8 +8,6 @@ require_relative '../turkish_cities/helpers/decomposer_helper'
8
8
  class City
9
9
  include DecomposerHelper
10
10
 
11
- I18n.enforce_available_locales = false
12
-
13
11
  file_path = File.join(File.dirname(__FILE__), 'data/cities.yaml')
14
12
  CITY_LIST = YAML.load_file(file_path)
15
13
 
@@ -67,7 +65,7 @@ class City
67
65
  def check_phone_code(input)
68
66
  return if input.to_i.even?
69
67
 
70
- raise ArgumentError, "Given value [#{input}] must be an even number."
68
+ raise ArgumentError, I18n.t('errors.not_even_input', input: input)
71
69
  end
72
70
 
73
71
  def filter_metropolitan_municipalities(city_list)
@@ -32,7 +32,7 @@ module NeighborhoodsParser
32
32
  end
33
33
 
34
34
  mahalle = []
35
- data_array[3].downcase(:turkic).strip.split(' ').each do |word|
35
+ data_array[3].downcase(:turkic).strip.split.each do |word|
36
36
  if word[0] == '('
37
37
  word[1] = word[1].capitalize!(:turkic) unless word[1].to_i.to_s == word[1]
38
38
  else
@@ -121,11 +121,14 @@ class Distance
121
121
 
122
122
  def description_text(travel_method, city_array, result_set)
123
123
  if travel_method == 'Air'
124
- return "#{travel_method} travel distance between #{city_array[0]['name']} and #{city_array[1]['name']} is " \
125
- "#{result_set[0]} km. Estimated air travel would take #{result_set[1]} minutes."
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])
126
128
  end
127
129
 
128
- "#{travel_method} travel distance between #{city_array[0]['name']} and #{city_array[1]['name']} is " \
129
- "#{result_set[0]} km."
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])
130
133
  end
131
134
  end
@@ -4,15 +4,15 @@ 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
8
  end
9
9
 
10
10
  def city_not_found_error(input)
11
- "Couldn't find city name with '#{input}'"
11
+ I18n.t('errors.city_not_found_error', input: input)
12
12
  end
13
13
 
14
14
  def cities_not_found_error(first, second)
15
- "Couldn't find cities combination with '#{first}/#{second}'"
15
+ I18n.t('errors.cities_not_found_error', first: first, second: second)
16
16
  end
17
17
 
18
18
  def convert_chars(string)
@@ -35,11 +35,11 @@ module DecomposerHelper
35
35
  end
36
36
 
37
37
  def district_not_found_error(district_input, city_input)
38
- "Couldn't find district name with '#{district_input}' of '#{city_input}'"
38
+ I18n.t('errors.district_not_found_error', district_input: district_input, city_input: city_input)
39
39
  end
40
40
 
41
41
  def postcode_not_found_error(postcode_input)
42
- "Couldn't find any subdistrict with postcode '#{postcode_input}'"
42
+ I18n.t('errors.postcode_not_found_error', postcode_input: postcode_input)
43
43
  end
44
44
 
45
45
  def prepare_city_list(city_list, options)
@@ -64,6 +64,7 @@ module DecomposerHelper
64
64
 
65
65
  def sort_alphabetically(list, options = nil)
66
66
  turkish_alphabet = ' -0123456789abcçdefgğhıijklmnoöprsştuüvyz'
67
+
67
68
  list.sort_by do |item|
68
69
  item_to_sort = if options.nil? || options[:with].nil?
69
70
  item
@@ -75,7 +76,8 @@ module DecomposerHelper
75
76
  end
76
77
 
77
78
  def subdistrict_not_found_error(subdistrict_input, district_input, city_input)
78
- "Couldn't find subdistrict with '#{subdistrict_input}' of '#{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)
79
81
  end
80
82
 
81
83
  private
@@ -99,6 +101,6 @@ module DecomposerHelper
99
101
  end
100
102
 
101
103
  def unsupported_travel_method(input)
102
- "Travel method '#{input}' is unsupported"
104
+ I18n.t('errors.unsupported_travel_method', input: input)
103
105
  end
104
106
  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.5.0'
5
5
  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'
@@ -24,7 +23,7 @@ Gem::Specification.new do |s|
24
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.3.1'
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.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: 2020-04-13 00:00:00.000000000 Z
11
+ date: 2021-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 1.3.1
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: 1.3.1
88
+ version: 1.16.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,6 +97,7 @@ 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"
@@ -110,6 +111,8 @@ files:
110
111
  - Gemfile.lock
111
112
  - LICENSE.txt
112
113
  - README.md
114
+ - config/locales/en.yml
115
+ - config/locales/tr.yml
113
116
  - lib/turkish_cities.rb
114
117
  - lib/turkish_cities/city.rb
115
118
  - lib/turkish_cities/data/cities.yaml
@@ -214,7 +217,7 @@ metadata:
214
217
  changelog_uri: https://github.com/sarslanoglu/turkish_cities/blob/master/CHANGELOG.md
215
218
  source_code_uri: https://github.com/sarslanoglu/turkish_cities
216
219
  bug_tracker_uri: https://github.com/sarslanoglu/turkish_cities/issues
217
- post_install_message:
220
+ post_install_message:
218
221
  rdoc_options: []
219
222
  require_paths:
220
223
  - lib
@@ -229,8 +232,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
232
  - !ruby/object:Gem::Version
230
233
  version: '0'
231
234
  requirements: []
232
- rubygems_version: 3.0.3
233
- signing_key:
235
+ rubygems_version: 3.2.17
236
+ signing_key:
234
237
  specification_version: 4
235
238
  summary: List and find Turkish cities
236
239
  test_files: []