Class: Geocoder::US::Map
- Inherits:
-
Hash
- Object
- Hash
- Geocoder::US::Map
- Defined in:
- lib/geocoder/us/constants.rb
Instance Attribute Summary collapse
-
#regexp ⇒ Object
The Map class provides a two-way mapping between postal abbreviations and their fully written equivalents.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #build_match ⇒ Object
-
#build_partial ⇒ Object
The build_partial method constructs a hash of case-insensitive, whitespace-delimited prefixes to keys and values in the two-way Map.
- #key?(key) ⇒ Boolean
-
#partial?(key) ⇒ Boolean
The partial? method returns true if the key is a prefix of some key in the Map.
Instance Attribute Details
#regexp ⇒ Object
The Map class provides a two-way mapping between postal abbreviations and their fully written equivalents. attr_accessor :partial
13 14 15 |
# File 'lib/geocoder/us/constants.rb', line 13 def regexp @regexp end |
Class Method Details
.[](*items) ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
44 45 46 |
# File 'lib/geocoder/us/constants.rb', line 44 def [] (key) super(key.downcase) end |
#build_match ⇒ Object
31 32 33 34 35 |
# 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 ⇒ Object
The build_partial method constructs a hash of case-insensitive, whitespace-delimited prefixes to keys and values in the two-way Map.
24 25 26 27 28 29 30 |
# 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) ⇒ Boolean
41 42 43 |
# File 'lib/geocoder/us/constants.rb', line 41 def key? (key) super(key.downcase) end |
#partial?(key) ⇒ Boolean
The partial? method returns true if the key is a prefix of some key in the Map.
38 39 40 |
# File 'lib/geocoder/us/constants.rb', line 38 def partial? (key) @partial.member? key.downcase end |