Skip to content

Instantly share code, notes, and snippets.

@jzellman
Created September 2, 2009 19:07
Show Gist options
  • Save jzellman/179905 to your computer and use it in GitHub Desktop.
Save jzellman/179905 to your computer and use it in GitHub Desktop.
class Company
def zipcode
Zipcode.parse(get_attribute(:zipcode), self.country)
end
end
# example zipcode interface
class Zipcode
def self.parse(zipcode, country)
Object.const_get("Zipcode::#{country.upcase}").new(zipcode)
end
# the local part of zipcode that is typically included in things
# subclass impl
def local
end
# if supported, additional 4 digits
def extension
end
end
some_mid = params[:mid]
zipcode = params[:zipcode]
Company.find_by_mid(some_mid).select{|c| c.zipcode.local.eql?(zipcode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment