Class: ViaCep::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/via_cep/instance.rb

Direct Known Subclasses

Address, SearchByAddress

Instance Method Summary collapse

Instance Method Details

#define_attributes(response) ⇒ Object

Default class to define methods based on the response

return [ViaCep::Instance]



10
11
12
13
14
15
16
17
18
19
# File 'lib/via_cep/instance.rb', line 10

def define_attributes(response)
  ViaCep::METHODS.each do |method_name, response_key|
    value = response[response_key.to_s]

    instance_variable_set("@#{method_name}", value)
    self.class.define_method(method_name) do
      instance_variable_get("@#{method_name}")
    end
  end
end