Class: Indirizzo::Map
- Inherits:
-
Hash
- Object
- Hash
- Indirizzo::Map
- Defined in:
- lib/indirizzo/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
Instance Attribute Details
#regexp ⇒ Object
The Map class provides a two-way mapping between postal abbreviations and their fully written equivalents. attr_accessor :partial
10 11 12 |
# File 'lib/indirizzo/constants.rb', line 10 def regexp @regexp end |
Class Method Details
.[](*items) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/indirizzo/constants.rb', line 11 def self.[] (*items) hash = super(*items) 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
26 27 28 |
# File 'lib/indirizzo/constants.rb', line 26 def [] (key) super(key.downcase) end |
#build_match ⇒ Object
18 19 20 21 22 |
# File 'lib/indirizzo/constants.rb', line 18 def build_match @regexp = Regexp.new( '\b(' + [keys,values].flatten.join("|") + ')\b', Regexp::IGNORECASE) end |
#key?(key) ⇒ Boolean
23 24 25 |
# File 'lib/indirizzo/constants.rb', line 23 def key? (key) super(key.downcase) end |