Class: Postcode

Inherits:
Object
  • Object
show all
Includes:
DecomposerHelper
Defined in:
lib/turkish_cities/postcode.rb

Instance Method Summary collapse

Methods included from DecomposerHelper

#check_input_range, #cities_not_found_error, #city_not_found_error, #city_population_not_found_error, #convert_chars, #create_district_list, #create_file_path, #district_not_found_error, #find_by_between, #postcode_not_found_error, #prepare_city_list, #sort_alphabetically, #sort_input_numbers, #subdistrict_not_found_error

Instance Method Details

#find_by_postcode(postcode) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/turkish_cities/postcode.rb', line 11

def find_by_postcode(postcode)
  check_input_range(postcode, 1010, 81_952)

  city_name = City.new.find_by_id(postcode.to_i / 1000)
  city_file = create_district_list(city_name)

  city_file.each do |district|
    district_name = district[0]
    district[1].each do |subdistrict|
      return [city_name, district_name, subdistrict[0]] if subdistrict[1]['postcode'] == postcode.to_i
    end
  end
  postcode_not_found_error(postcode)
end