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.


11
12
13
# File 'lib/poczta_polska/package.rb', line 11

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


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

def data
  @data
end

Instance Method Details

#country_fromSymbol

Returns origin country code.

Returns:

  • (Symbol)

    origin country code


31
32
33
# File 'lib/poczta_polska/package.rb', line 31

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

#country_from_strString

Returns origin country name.

Returns:

  • (String)

    origin country name


36
37
38
# File 'lib/poczta_polska/package.rb', line 36

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

#country_toSymbol

Returns destination country code.

Returns:

  • (Symbol)

    destination country code


41
42
43
# File 'lib/poczta_polska/package.rb', line 41

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

#country_to_strString

Returns destination country name.

Returns:

  • (String)

    destination country name


46
47
48
# File 'lib/poczta_polska/package.rb', line 46

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:


90
91
92
# File 'lib/poczta_polska/package.rb', line 90

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

#idString

Returns package ID.

Returns:

  • (String)

    package ID


16
17
18
# File 'lib/poczta_polska/package.rb', line 16

def id
  @data[:numer].to_s
end

#massFloat

Returns mass of the package.

Returns:

  • (Float)

    mass of the package


61
62
63
# File 'lib/poczta_polska/package.rb', line 61

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

#office_fromString

Returns origin post office name.

Returns:

  • (String)

    origin post office name


51
52
53
# File 'lib/poczta_polska/package.rb', line 51

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:


74
75
76
77
# File 'lib/poczta_polska/package.rb', line 74

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


56
57
58
# File 'lib/poczta_polska/package.rb', line 56

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:


83
84
85
86
# File 'lib/poczta_polska/package.rb', line 83

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.)


66
67
68
# File 'lib/poczta_polska/package.rb', line 66

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

#typeSymbol

Returns package type code.

Returns:

  • (Symbol)

    package type code


21
22
23
# File 'lib/poczta_polska/package.rb', line 21

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

#type_strString

Returns human-readable package type.

Returns:

  • (String)

    human-readable package type


26
27
28
# File 'lib/poczta_polska/package.rb', line 26

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