Sha256: e5db941f3b49b3369613e93027eef2f44e54a566d652da584b2b20397addd86f

Contents?: true

Size: 436 Bytes

Versions: 11

Compression:

Stored size: 436 Bytes

Contents

module PagarMe
  class Zipcode < PagarMeObject
    ZIPCODE_REGEXP = /\d{5}[-\.\_\s]?\d{3}/

    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

    def self.valid_zipcode?(zipcode)
      zipcode.match ZIPCODE_REGEXP
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pagarme-2.4.0 lib/pagarme/resources/postal_code.rb
pagarme-2.3.0 lib/pagarme/resources/postal_code.rb
pagarme-2.2.3 lib/pagarme/resources/postal_code.rb
pagarme-2.2.2 lib/pagarme/resources/postal_code.rb
pagarme-2.2.1 lib/pagarme/resources/postal_code.rb
pagarme-2.2.0 lib/pagarme/resources/postal_code.rb
pagarme-2.1.4 lib/pagarme/resources/postal_code.rb
pagarme-2.1.3 lib/pagarme/resources/postal_code.rb
pagarme-2.1.2 lib/pagarme/resources/postal_code.rb
pagarme-2.1.1 lib/pagarme/resources/postal_code.rb
pagarme-2.1.0 lib/pagarme/resources/postal_code.rb