Class: AdWords::PostalCodeDb
- Inherits:
-
Object
- Object
- AdWords::PostalCodeDb
- Defined in:
- lib/adwords_location/postal_code.rb
Instance Method Summary collapse
- #all_postal_codes ⇒ Object
- #cities_by_postal_code(postal_code) ⇒ Object
- #find_records_by_postal_code(postal_code) ⇒ Object
- #include?(postal_code) ⇒ Boolean
-
#initialize ⇒ PostalCodeDb
constructor
A new instance of PostalCodeDb.
- #size ⇒ Object
Constructor Details
#initialize ⇒ PostalCodeDb
Returns a new instance of PostalCodeDb.
34 35 36 37 38 39 40 41 |
# File 'lib/adwords_location/postal_code.rb', line 34 def initialize @postal_code_records = {} PostalCode.all.each do |r| @postal_code_records[r.postal_code] ||= [] @postal_code_records[r.postal_code] << r end @postal_code_records.freeze end |
Instance Method Details
#all_postal_codes ⇒ Object
65 66 67 |
# File 'lib/adwords_location/postal_code.rb', line 65 def all_postal_codes @postal_code_records.keys end |
#cities_by_postal_code(postal_code) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/adwords_location/postal_code.rb', line 55 def cities_by_postal_code(postal_code) if include? postal_code then @postal_code_records[postal_code].map do |record| record.city_canonical_name end else [] end end |
#find_records_by_postal_code(postal_code) ⇒ Object
47 48 49 |
# File 'lib/adwords_location/postal_code.rb', line 47 def find_records_by_postal_code(postal_code) @postal_code_records[postal_code] end |
#include?(postal_code) ⇒ Boolean
51 52 53 |
# File 'lib/adwords_location/postal_code.rb', line 51 def include?(postal_code) @postal_code_records.include? postal_code end |
#size ⇒ Object
43 44 45 |
# File 'lib/adwords_location/postal_code.rb', line 43 def size @postal_code_records.size end |