Class: PagarMe::Zipcode
- Inherits:
-
PagarMeObject
- Object
- PagarMeObject
- PagarMe::Zipcode
- Defined in:
- lib/pagarme/resources/postal_code.rb
Constant Summary collapse
- ZIPCODE_REGEXP =
/\d{5}[-\.\_\s]?\d{3}/
Constants inherited from PagarMeObject
Instance Attribute Summary
Attributes inherited from PagarMeObject
Class Method Summary collapse
Methods inherited from PagarMeObject
#==, #[]=, convert, #empty?, #initialize, #respond_to?, #to_hash, #to_s, #unsaved_attributes
Constructor Details
This class inherits a constructor from PagarMe::PagarMeObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PagarMe::PagarMeObject
Class Method Details
.find(zipcode) ⇒ Object
5 6 7 8 9 |
# File 'lib/pagarme/resources/postal_code.rb', line 5 def self.find(zipcode) raise PagarMe::RequestError.new('invalid zipcode') unless valid_zipcode?(zipcode) sanitized_zipcode = zipcode.gsub(/[-\.\_\s]/, '') self.new PagarMe::Request.get("/zipcodes/#{sanitized_zipcode}").run end |
.valid_zipcode?(zipcode) ⇒ Boolean
11 12 13 |
# File 'lib/pagarme/resources/postal_code.rb', line 11 def self.valid_zipcode?(zipcode) zipcode.match ZIPCODE_REGEXP end |