Class: Encomenda

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numero) ⇒ Encomenda

Returns a new instance of Encomenda.



6
7
8
9
# File 'lib/encomenda.rb', line 6

def initialize(numero)
  @numero = numero
  @status = Array.new
end

Instance Attribute Details

#numeroObject (readonly)

Returns the value of attribute numero.



4
5
6
# File 'lib/encomenda.rb', line 4

def numero
  @numero
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/encomenda.rb', line 4

def status
  @status
end

Instance Method Details

#<<(status) ⇒ Object



11
12
13
14
15
16
# File 'lib/encomenda.rb', line 11

def <<(status)
  @status << status
  @status.sort! do |a,b| 
    a.data <=> b.data
  end
end

#primeiro_status_disponivelObject



22
23
24
# File 'lib/encomenda.rb', line 22

def primeiro_status_disponivel
  @status.first
end

#to_xmlObject

TODO: refactor - nao sei se deveria estar aqui…



27
28
29
30
31
32
33
# File 'lib/encomenda.rb', line 27

def to_xml
  xml = "<encomenda numero=\"#{@numero}\">"
  @status.each do |status|
    xml += status.to_xml
  end
  xml += "</encomenda>"
end

#ultimo_status_disponivelObject



18
19
20
# File 'lib/encomenda.rb', line 18

def ultimo_status_disponivel
  @status.last
end