Class: PocztaPolska::Package

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

Overview

The Package class contains all necessary information about a tracked package.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Package

Returns a new instance of Package.



8
9
10
# File 'lib/poczta_polska/package.rb', line 8

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataHash (readonly)

Returns Original data from the XML response.

Returns:

  • (Hash)

    Original data from the XML response



6
7
8
# File 'lib/poczta_polska/package.rb', line 6

def data
  @data
end

Instance Method Details

#country_fromSymbol

Returns origin country code.

Returns:

  • (Symbol)

    origin country code



28
29
30
# File 'lib/poczta_polska/package.rb', line 28

def country_from
  @data[:dane_przesylki][:kod_kraju_nadania].to_sym
end

#country_from_strString

Returns origin country name.

Returns:

  • (String)

    origin country name



33
34
35
# File 'lib/poczta_polska/package.rb', line 33

def country_from_str
  @data[:dane_przesylki][:kraj_nadania].to_s
end

#country_toSymbol

Returns destination country code.

Returns:

  • (Symbol)

    destination country code



38
39
40
# File 'lib/poczta_polska/package.rb', line 38

def country_to
  @data[:dane_przesylki][:kod_kraju_przezn].to_sym
end

#country_to_strString

Returns destination country name.

Returns:

  • (String)

    destination country name



43
44
45
# File 'lib/poczta_polska/package.rb', line 43

def country_to_str
  @data[:dane_przesylki][:kraj_przezn].to_s
end

#eventsArray<Event>

Returns a list of all events connected with the package

Returns:



87
88
89
# File 'lib/poczta_polska/package.rb', line 87

def events
  @data[:dane_przesylki][:zdarzenia][:zdarzenie]&.map { |e| Event.new(e) } || []
end

#idString

Returns package ID.

Returns:

  • (String)

    package ID



13
14
15
# File 'lib/poczta_polska/package.rb', line 13

def id
  @data[:numer].to_s
end

#massFloat

Returns mass of the package.

Returns:

  • (Float)

    mass of the package



58
59
60
# File 'lib/poczta_polska/package.rb', line 58

def mass
  @data[:dane_przesylki][:masa]
end

#office_fromString

Returns origin post office name.

Returns:

  • (String)

    origin post office name



48
49
50
# File 'lib/poczta_polska/package.rb', line 48

def office_from
  @data[:dane_przesylki][:urzad_nadania][:nazwa].to_s
end

#office_from_detailsOffice

Returns detailed information about the origin post office, only if the Tracker#check/Tracker#check_many method was called with details set to true.

Returns:



71
72
73
74
# File 'lib/poczta_polska/package.rb', line 71

def office_from_details
  office = @data[:dane_przesylki][:urzad_nadania][:dane_szczegolowe]
  Office.new(office) unless office.nil?
end

#office_toString

Returns destination post office name.

Returns:

  • (String)

    destination post office name



53
54
55
# File 'lib/poczta_polska/package.rb', line 53

def office_to
  @data[:dane_przesylki][:urzad_przezn][:nazwa].to_s
end

#office_to_detailsOffice

Returns detailed information about the destination post office, only if the Tracker#check/Tracker#check_many method was called with details set to true.

Returns:



80
81
82
83
# File 'lib/poczta_polska/package.rb', line 80

def office_to_details
  office = @data[:dane_przesylki][:urzad_przezn][:dane_szczegolowe]
  Office.new(office) unless office.nil?
end

#ready?Boolean

Returns whether the service has been finished (delivered, received in the post office, etc.).

Returns:

  • (Boolean)

    whether the service has been finished (delivered, received in the post office, etc.)



63
64
65
# File 'lib/poczta_polska/package.rb', line 63

def ready?
  @data[:dane_przesylki][:zakonczono_obsluge]
end

#typeSymbol

Returns package type code.

Returns:

  • (Symbol)

    package type code



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

def type
  @data[:dane_przesylki][:kod_rodz_przes].to_sym
end

#type_strString

Returns human-readable package type.

Returns:

  • (String)

    human-readable package type



23
24
25
# File 'lib/poczta_polska/package.rb', line 23

def type_str
  @data[:dane_przesylki][:rodz_przes].to_s
end