Skip to content

Commit

Permalink
improve District methods (#52)
Browse files Browse the repository at this point in the history
* improve District methods

* update CHANGELOG.md
  • Loading branch information
serpilacar authored Jul 28, 2020
1 parent dcb779f commit 2b9b0ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 3 additions & 14 deletions lib/turkish_cities/district.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 2b9b0ba

Please sign in to comment.