class Geocoder::US::Map

Attributes

regexp[RW]
The Map class provides a two-way mapping between postal abbreviations
and their fully written equivalents.

attr_accessor :partial

Public Class Methods

[](*items) click to toggle source
Calls superclass method
# File lib/geocoder/us/constants.rb, line 14
def self.[] (*items)
  hash = super(*items)
  #hash.build_partial
  hash.build_match
  hash.keys.each {|k| hash[k.downcase] = hash.fetch(k)}
  hash.values.each {|v| hash[v.downcase] = v}
  hash.freeze
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/geocoder/us/constants.rb, line 44
def [] (key)
  super(key.downcase)
end
build_match() click to toggle source
# File lib/geocoder/us/constants.rb, line 31
def build_match
  @regexp = Regexp.new(
    '\b(' + [keys,values].flatten.join("|") + ')\b',
    Regexp::IGNORECASE)
end
build_partial() click to toggle source

The build_partial method constructs a hash of case-insensitive, whitespace-delimited prefixes to keys and values in the two-way Map.

# File lib/geocoder/us/constants.rb, line 24
def build_partial
  @partial = Set.new()
  [keys, values].flatten.each {|item|
    @partial << item.downcase
    item.downcase.split.each {|token| @partial << token}
  }
end
key?(key) click to toggle source
Calls superclass method
# File lib/geocoder/us/constants.rb, line 41
def key? (key)
  super(key.downcase)
end
partial?(key) click to toggle source

The partial? method returns true if the key is a prefix of some key in the Map.

# File lib/geocoder/us/constants.rb, line 38
def partial? (key)
  @partial.member? key.downcase
end