Class: Cep::CepService

Inherits:
Object
  • Object
show all
Defined in:
lib/brval/cep/cep_service.rb

Direct Known Subclasses

Postmon, ViaCep, Widenet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cep) ⇒ CepService

Returns a new instance of CepService.



5
6
7
# File 'lib/brval/cep/cep_service.rb', line 5

def initialize cep
  @cep = cep.to_s.tr('^0-9', '')
end

Instance Attribute Details

#cepObject

Returns the value of attribute cep.



3
4
5
# File 'lib/brval/cep/cep_service.rb', line 3

def cep
  @cep
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/brval/cep/cep_service.rb', line 3

def url
  @url
end

Instance Method Details

#checkObject



9
10
11
12
13
# File 'lib/brval/cep/cep_service.rb', line 9

def check
  return false if @cep.nil? || @cep.length > 8
  json = load_cep_json
  json_valid?(json)
end

#infoObject



15
16
17
18
19
# File 'lib/brval/cep/cep_service.rb', line 15

def info
  return response_error if @cep.nil? || @cep.length > 8
  json = load_cep_json
  json_valid?(json) ? translate_params(json) : response_error
end