lib/viacep/address.rb in viacep-2.0.1 vs lib/viacep/address.rb in viacep-2.0.2
- old
+ new
@@ -4,10 +4,18 @@
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 = {})
+ if cep.nil?
+ raise ArgumentError, 'CEP cannot be nil'
+ end
+
cep = cep.to_s.delete('^0-9')
+
+ if cep.length != 8
+ raise ArgumentError, 'CEP must have 8 digits'
+ end
response = Service.fetch cep, options[:timeout]
fill_from response
end