From 2b9b0baea2ea7eba605ec89e92504a5655874a40 Mon Sep 17 00:00:00 2001 From: Serpil Acar Date: Tue, 28 Jul 2020 21:31:39 +0300 Subject: [PATCH] improve District methods (#52) * improve District methods * update CHANGELOG.md --- CHANGELOG.md | 1 + lib/turkish_cities/district.rb | 17 +++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9bf3d..bd72b1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changes * [#45](https://github.com/sarslanoglu/turkish_cities/issues/45): Refactor `District` class +* [#50](https://github.com/sarslanoglu/turkish_cities/issues/50): Additional improvements on `District` class methods ## 0.2.1 (2020-06-29) diff --git a/lib/turkish_cities/district.rb b/lib/turkish_cities/district.rb index edd2946..7a4c079 100644 --- a/lib/turkish_cities/district.rb +++ b/lib/turkish_cities/district.rb @@ -17,10 +17,7 @@ def initialize(city_name, district_name) def subdistricts return district_not_found_error(@district_name, @city_name) if district_item.nil? - subdistricts = [] - district_item.each { |subdistrict| subdistricts << subdistrict[0] } - - sort_alphabetically(subdistricts) + sort_alphabetically(district_item.keys) end def neighborhoods(subdistrict_name) @@ -43,19 +40,11 @@ def create_neighborhoods(subdistrict_name) end def create_neighborhoods_without_subdistrict_name - neighborhoods = [] - district_item.each do |subdistrict| - subdistrict[1]['neighborhoods'].each { |neighborhood| neighborhoods << neighborhood } - end - neighborhoods + district_item.values.map { |subdistrict| subdistrict['neighborhoods'] }.flatten end def create_neighborhoods_with_subdistrict_name(subdistrict_name) - neighborhoods = [] - district_item[subdistrict_name]['neighborhoods'].each do |neighborhood| - neighborhoods << neighborhood - end - neighborhoods + district_item[subdistrict_name]['neighborhoods'] end def district_item