Class: Correios::Frete::Pacote

Inherits:
Object
  • Object
show all
Defined in:
lib/correios/frete/pacote.rb

Constant Summary collapse

MIN_DIMENSIONS =
{
  :comprimento => 16.0,
  :largura => 11.0,
  :altura => 2.0
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(itens = nil) ⇒ Pacote

Returns a new instance of Pacote.



13
14
15
16
17
18
# File 'lib/correios/frete/pacote.rb', line 13

def initialize(itens = nil)
  @peso = @comprimento = @largura = @altura = @volume = 0.0
  @itens = []

  itens.each { |item| adicionar_item(item) } if itens
end

Instance Attribute Details

#alturaObject (readonly)

Returns the value of attribute altura.



5
6
7
# File 'lib/correios/frete/pacote.rb', line 5

def altura
  @altura
end

#comprimentoObject (readonly)

Returns the value of attribute comprimento.



5
6
7
# File 'lib/correios/frete/pacote.rb', line 5

def comprimento
  @comprimento
end

#larguraObject (readonly)

Returns the value of attribute largura.



5
6
7
# File 'lib/correios/frete/pacote.rb', line 5

def largura
  @largura
end

#pesoObject (readonly)

Returns the value of attribute peso.



5
6
7
# File 'lib/correios/frete/pacote.rb', line 5

def peso
  @peso
end

#volumeObject (readonly)

Returns the value of attribute volume.



5
6
7
# File 'lib/correios/frete/pacote.rb', line 5

def volume
  @volume
end

Instance Method Details

#adicionar_item(item) ⇒ Object Also known as: add_item



29
30
31
32
33
34
35
36
37
# File 'lib/correios/frete/pacote.rb', line 29

def adicionar_item(item)
  return unless item

  item = Correios::Frete::PacoteItem.new(item) if item.is_a?(Hash)
  @itens << item

  calcular_medidas(item)
  item
end

#formatoObject



20
21
22
# File 'lib/correios/frete/pacote.rb', line 20

def formato
  :caixa_pacote
end

#itensObject Also known as: items



24
25
26
# File 'lib/correios/frete/pacote.rb', line 24

def itens
  @itens
end