Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change city_lookup to load all configured cities #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions lib/city-state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,23 @@ def self.cities(state, country = nil)
end

# Process lookup table
lookup = get_cities_lookup(country, state)
lookup = get_cities_lookup(country)
if ! lookup.nil?
lookup.each do |old_value, new_value|
if new_value.nil? || self.blank?(new_value)
@cities[country][state].delete(old_value)
else
index = @cities[country][state].index(old_value)
if index.nil?
@cities[country][state][] = new_value
lookup.each do |state, new_values|
new_values.each do |old_value, new_value|
if new_value.nil? || self.blank?(new_value)
@cities[country][state].delete(old_value)
else
@cities[country][state][index] = new_value
index = @cities[country][state].index(old_value)
if index.nil?
@cities[country][state] << new_value
else
@cities[country][state][index] = new_value
end
end
end
end

@cities[country][state] = @cities[country][state].sort # sort it alphabetically
end
end
Expand All @@ -210,7 +213,7 @@ def self.set_countries_lookup_file(filename)
@countries_lookup = nil
end

def self.get_cities_lookup(country, state)
def self.get_cities_lookup(country)
# lookup file not loaded
if @cities_lookup.nil?
@cities_lookup_fn = DEFAULT_CITIES_LOOKUP_FN if @cities_lookup_fn.nil?
Expand All @@ -220,8 +223,8 @@ def self.get_cities_lookup(country, state)
@cities_lookup.each { |key, value| @cities_lookup[key] = self.symbolize_keys(value) } # force states to be symbols
end

return nil if ! @cities_lookup.key?(country) || ! @cities_lookup[country].key?(state)
@cities_lookup[country][state]
return nil if ! @cities_lookup.key?(country)
@cities_lookup[country]
end

def self.get_states_lookup(country)
Expand Down