Class: CheckYoSpelling::USA

Inherits:
Object
  • Object
show all
Defined in:
lib/check_yo_spelling/usa.rb

Constant Summary collapse

MIN_DISTANCE =

Use the Levenshtein gem to find the closest match NOTE: the gem treats replacement edits as a distance of 2

4

Class Method Summary collapse

Class Method Details

.check_city(city, state) ⇒ Object

Find the closest existing city in the state



8
9
10
11
12
13
14
15
# File 'lib/check_yo_spelling/usa.rb', line 8

def check_city city, state
  full_state = Geolookup::USA::State.abbreviation_to_name state
  return nil if full_state.nil?
  @@city_arrays ||= Hash.new
  filename = "#{full_state.downcase.gsub(" ", "_")}_cities.yml"
  @@city_arrays[filename] ||= words(filename)
  check city, @@city_arrays[filename]
end

.check_state(state) ⇒ Object

Find the closest existing state



18
19
20
21
# File 'lib/check_yo_spelling/usa.rb', line 18

def check_state state
  @@states ||= words("states.yml")
  check state, @@states
end