Method: Worldwide::Zip#outcode
- Defined in:
- lib/worldwide/zip.rb
#outcode(country_code:, zip:) ⇒ Object
Returns the “outcode” (first portion) of a postcode for a country that uses the UK style. Returns the “forward sortation area” (first portion) of a postal code for Canada. Returns the “routing key” (first portion) of a postal code for Ireland. Otherwise, returns the full zip.
157 158 159 160 161 162 163 |
# File 'lib/worldwide/zip.rb', line 157 def outcode(country_code:, zip:) @split_code_countries ||= Set.new(GB_STYLE_ZIP_COUNTRIES).add("CA").add("IE") return zip unless @split_code_countries.include?(country_code.to_s.upcase) normalize(country_code: country_code, zip: zip)&.split(" ")&.first end |