Class: ValidZipCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/valid_zip_codes.rb

Constant Summary collapse

SUPPORTED_COUNTRIES =
["DK", "SE"]

Instance Method Summary collapse

Constructor Details

#initializeValidZipCodes

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

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/valid_zip_codes.rb', line 28

def supports_country?(country)
	SUPPORTED_COUNTRIES.include?(country)
end