Class: Correios::Cep

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

Direct Known Subclasses

Cep

Constant Summary collapse

Setup =
Correios::Setup.new
AttrReaders =
[
  :location,
  :type,
  :neighborhood,
  :city,
  :state
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cep) ⇒ Cep

Returns a new instance of Cep.



23
24
25
# File 'lib/ceps/cep.rb', line 23

def initialize(cep)
  @data = cep.is_a?(Hash) ? cep : Setup.ceps[cep]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



21
22
23
# File 'lib/ceps/cep.rb', line 21

def data
  @data
end

Class Method Details

.new(cep) ⇒ Object



39
40
41
42
43
# File 'lib/ceps/cep.rb', line 39

def new(cep)
  if cep.is_a?(Hash) || Setup.ceps.keys.include?(cep)
    super
  end
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/ceps/cep.rb', line 31

def ==(other)
  other == data
end

#valid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ceps/cep.rb', line 27

def valid?
  !(@data.nil? || @data.empty?)
end