module Spellchecker::Dictionaries::UsToponyms

Constants

MUTEX
PATH

github.com/grammakov/USA-cities-and-states

Public Instance Methods

all() click to toggle source

@return [Set<String>]

# File lib/spellchecker/dictionaries/us_toponyms.rb, line 13
def all
  @all || MUTEX.synchronize do
    @all ||= load_names
  end
end
include?(name) click to toggle source

@param name [String] @return [Boolean]

# File lib/spellchecker/dictionaries/us_toponyms.rb, line 21
def include?(name)
  return false unless name

  all.include?(Utils.remove_suffix(name))
end
load_names() click to toggle source

@return [Set<String>]

# File lib/spellchecker/dictionaries/us_toponyms.rb, line 28
def load_names
  csv = CSV.parse(PATH.read, headers: true, col_sep: '|')

  csv.each_with_object(Set.new) do |row, set|
    set.add(row['City']) if row['City']
    set.add(row['State full']) if row['State full']
    set.add(row['County'].to_s.split(/\s+/).map(&:capitalize).join(' ')) unless row['County'].to_s.empty?
    set.add(row['City alias']) if row['City alias']
  end
end