Class: ViaCep::Address
- Inherits:
-
Object
- Object
- ViaCep::Address
- Defined in:
- lib/viacep/address.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#cep ⇒ Object
readonly
Returns the value of attribute cep.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#gia ⇒ Object
readonly
Returns the value of attribute gia.
-
#ibge ⇒ Object
readonly
Returns the value of attribute ibge.
-
#neighborhood ⇒ Object
readonly
Returns the value of attribute neighborhood.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(cep, options = {}) ⇒ ViaCep::Address
constructor
Initializes an instance of ViaCep::Address and fetches the CEP using the external API.
Constructor Details
#initialize(cep, options = {}) ⇒ ViaCep::Address
Initializes an instance of ViaCep::Address and fetches the CEP using the external API.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/viacep/address.rb', line 28 def initialize(cep, = {}) 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, [:timeout] fill_from response end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def address @address end |
#cep ⇒ Object (readonly)
Returns the value of attribute cep.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def cep @cep end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def city @city end |
#gia ⇒ Object (readonly)
Returns the value of attribute gia.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def gia @gia end |
#ibge ⇒ Object (readonly)
Returns the value of attribute ibge.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def ibge @ibge end |
#neighborhood ⇒ Object (readonly)
Returns the value of attribute neighborhood.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def neighborhood @neighborhood end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/viacep/address.rb', line 5 def state @state end |