Class: ValidZipCodes
- Inherits:
-
Object
- Object
- ValidZipCodes
- Defined in:
- lib/valid_zip_codes.rb
Constant Summary collapse
- SUPPORTED_COUNTRIES =
["DK", "SE", "FO", "GL"]
Instance Method Summary collapse
- #get_city_name(country, zip) ⇒ Object
-
#initialize ⇒ ValidZipCodes
constructor
A new instance of ValidZipCodes.
- #is_valid_zip?(country, zip) ⇒ Boolean
- #supports_country?(country) ⇒ Boolean
Constructor Details
#initialize ⇒ ValidZipCodes
Returns a new instance of ValidZipCodes.
7 8 9 |
# File 'lib/valid_zip_codes.rb', line 7 def initialize load_zips end |
Instance Method Details
#get_city_name(country, zip) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/valid_zip_codes.rb', line 19 def get_city_name(country, zip) if supports_country?(country) sr = country_hash(country).select{|z| z["zip"] == zip.to_s} sr.count > 0 ? sr.first["city"] : raise("Zip not found") else raise "Country not supported" end end |
#is_valid_zip?(country, zip) ⇒ Boolean
11 12 13 14 15 16 17 |
# File 'lib/valid_zip_codes.rb', line 11 def is_valid_zip?(country, zip) if supports_country?(country) country_hash(country).select{|z| z["zip"] == zip.to_s}.count > 0 else raise "Country not supported" end end |
#supports_country?(country) ⇒ Boolean
28 29 30 |
# File 'lib/valid_zip_codes.rb', line 28 def supports_country?(country) SUPPORTED_COUNTRIES.include?(country) end |