Class: City
Constant Summary
collapse
- CITY_LIST =
YAML.load_file(file_path)
Instance Method Summary
collapse
#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_id(plate_number) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/turkish_cities/city.rb', line 14
def find_by_id(plate_number)
check_input_range(plate_number, 1, 81)
CITY_LIST.each do |city|
return city['name'] if city['plate_number'] == plate_number.to_i
end
end
|
#find_by_name(city_name, return_type) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/turkish_cities/city.rb', line 37
def find_by_name(city_name, return_type)
CITY_LIST.each do |city|
if convert_chars(city['name']) == convert_chars(city_name)
return return_type == 'plate_number' ? city['plate_number'] : city['phone_code']
end
end
city_not_found_error(city_name)
end
|
#find_by_phone_code(phone_code) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/turkish_cities/city.rb', line 22
def find_by_phone_code(phone_code)
check_input_range(phone_code, 212, 488)
check_phone_code(phone_code)
CITY_LIST.each do |city|
case city['phone_code']
when Array
return city['name'] if city['phone_code'].include?(phone_code.to_i)
when phone_code.to_i
return city['name']
end
end
city_not_found_error(phone_code)
end
|
#list_cities(options) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/turkish_cities/city.rb', line 46
def list_cities(options)
city_list = CITY_LIST
city_list = filter_metropolitan_municipalities(city_list) if options[:metropolitan_municipality]
city_list = filter_regions(city_list, options[:region]) if options[:region]
final_list = prepare_city_list(city_list, options)
options[:alphabetically_sorted] ? sort_alphabetically(final_list, options) : final_list
end
|
#list_districts(city_name) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/turkish_cities/city.rb', line 56
def list_districts(city_name)
CITY_LIST.each do |city|
return city['districts'] if convert_chars(city['name']) == convert_chars(city_name)
end
city_not_found_error(city_name)
end
|