Sha256: b0ee8a2cec368a59921ab0347b03dd7a7f998f9f0e855b03610593dd6d17eddc

Contents?: true

Size: 722 Bytes

Versions: 1

Compression:

Stored size: 722 Bytes

Contents

require_relative 'service'

module ViaCep
  class Address
    attr_reader :cep, :address, :neighborhood, :city, :state, :ibge, :gia

    # Initializes an instance of Address and fetches the CEP using the external API
    def initialize(cep, options = {})
      cep = cep.to_s.delete('^0-9')

      response = Service.fetch cep, options[:timeout]
      fill_from response
    end

    private

    def fill_from(response)
      @cep          = response['cep']
      @address      = response['logradouro']
      @neighborhood = response['bairro']
      @city         = response['localidade']
      @state        = response['uf']
      @ibge         = response['ibge']
      @gia          = response['gia']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
viacep-2.0.1 lib/viacep/address.rb