Class: RussianPost::Parcel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode, opts = {}) ⇒ Parcel

Returns a new instance of Parcel.



9
10
11
12
# File 'lib/russianpost/parcel.rb', line 9

def initialize(barcode, opts = {})
  @barcode = Barcode.new(barcode)
  @client  = (opts[:client] || Client).instance
end

Instance Attribute Details

#barcodeObject (readonly)

Returns the value of attribute barcode.



7
8
9
# File 'lib/russianpost/parcel.rb', line 7

def barcode
  @barcode
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/russianpost/parcel.rb', line 7

def client
  @client
end

Instance Method Details

#locationObject



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

def location
  operations.last.operation_address unless operations.empty?
end

#massObject



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

def mass
  operations.map{ |o| o.mass }.max
end

#operationsObject



14
15
16
# File 'lib/russianpost/parcel.rb', line 14

def operations
  @operations ||= fetch_operations
end

#rankObject



26
27
28
# File 'lib/russianpost/parcel.rb', line 26

def rank
  operations.map{ |o| o.mail_rank }.compact.last
end

#recipientObject



30
31
32
# File 'lib/russianpost/parcel.rb', line 30

def recipient
  operations.map{ |o| o.rcpn }.compact.last
end

#typeObject



34
35
36
# File 'lib/russianpost/parcel.rb', line 34

def type
  operations.last.mail_type unless operations.empty?
end