module PostalCode

Constants

CityOffset
DB
FS
RS
StateOffset
VERSION

Public Class Methods

city(postal_code) click to toggle source

Return the city for the given postal code.

# File lib/postal_code.rb, line 36
def self.city postal_code
  fetch(postal_code)[CityOffset]
end
clear_cache() click to toggle source

Clear the in-memory postal code cache.

# File lib/postal_code.rb, line 29
def self.clear_cache
  @cache.clear
end
load_cache() click to toggle source

Load the entire postal code database into memory.

# File lib/postal_code.rb, line 16
def self.load_cache
  open(DB) do |db|
    db.each_line do |line|
      line.rstrip!  # remove RS
      pcode, city, state = line.split(FS)
      @cache[pcode] = [city, state]
    end
  end
end
state(postal_code) click to toggle source

Return the state (two-letter abbreviation) for the given postal code.

# File lib/postal_code.rb, line 43
def self.state postal_code
  fetch(postal_code)[StateOffset]
end