class District
Public Class Methods
new(city_name, district_name)
click to toggle source
# File lib/turkish_cities/district.rb, line 11 def initialize(city_name, district_name) @city_name = city_name @district_name = district_name @district_list = create_district_list(city_name) end
Public Instance Methods
neighborhoods(subdistrict_name)
click to toggle source
# File lib/turkish_cities/district.rb, line 23 def neighborhoods(subdistrict_name) return district_not_found_error(@district_name, @city_name) if district_item.nil? neighborhoods = create_neighborhoods(subdistrict_name) neighborhoods.is_a?(Array) ? sort_alphabetically(neighborhoods) : neighborhoods end
subdistricts()
click to toggle source
# File lib/turkish_cities/district.rb, line 17 def subdistricts return district_not_found_error(@district_name, @city_name) if district_item.nil? sort_alphabetically(district_item.keys) end
Private Instance Methods
create_neighborhoods(subdistrict_name)
click to toggle source
# File lib/turkish_cities/district.rb, line 32 def create_neighborhoods(subdistrict_name) return create_neighborhoods_without_subdistrict_name if subdistrict_name.nil? if district_item[subdistrict_name].nil? return subdistrict_not_found_error(subdistrict_name, @district_name, @city_name) end create_neighborhoods_with_subdistrict_name(subdistrict_name) end
create_neighborhoods_with_subdistrict_name(subdistrict_name)
click to toggle source
# File lib/turkish_cities/district.rb, line 46 def create_neighborhoods_with_subdistrict_name(subdistrict_name) district_item[subdistrict_name]['neighborhoods'] end
create_neighborhoods_without_subdistrict_name()
click to toggle source
# File lib/turkish_cities/district.rb, line 42 def create_neighborhoods_without_subdistrict_name district_item.values.map { |subdistrict| subdistrict['neighborhoods'] }.flatten end
district_item()
click to toggle source
# File lib/turkish_cities/district.rb, line 50 def district_item @district_list[@district_name] end