class PocztaPolska::Package

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

Attributes

data[R]

@return [Hash] Original data from the XML response

Public Class Methods

new(data) click to toggle source
# File lib/poczta_polska/package.rb, line 8
def initialize(data)
  @data = data
end

Public Instance Methods

country_from() click to toggle source

@return [Symbol] origin country code

# File lib/poczta_polska/package.rb, line 28
def country_from
  @data[:dane_przesylki][:kod_kraju_nadania].to_sym
end
country_from_str() click to toggle source

@return [String] origin country name

# File lib/poczta_polska/package.rb, line 33
def country_from_str
  @data[:dane_przesylki][:kraj_nadania].to_s
end
country_to() click to toggle source

@return [Symbol] destination country code

# File lib/poczta_polska/package.rb, line 38
def country_to
  @data[:dane_przesylki][:kod_kraju_przezn].to_sym
end
country_to_str() click to toggle source

@return [String] destination country name

# File lib/poczta_polska/package.rb, line 43
def country_to_str
  @data[:dane_przesylki][:kraj_przezn].to_s
end
events() click to toggle source

Returns a list of all events connected with the package @return [Array<Event>]

# File lib/poczta_polska/package.rb, line 87
def events
  @data[:dane_przesylki][:zdarzenia][:zdarzenie]&.map { |e| Event.new(e) } || []
end
id() click to toggle source

@return [String] package ID

# File lib/poczta_polska/package.rb, line 13
def id
  @data[:numer].to_s
end
mass() click to toggle source

@return [Float] mass of the package

# File lib/poczta_polska/package.rb, line 58
def mass
  @data[:dane_przesylki][:masa]
end
office_from() click to toggle source

@return [String] origin post office name

# File lib/poczta_polska/package.rb, line 48
def office_from
  @data[:dane_przesylki][:urzad_nadania][:nazwa].to_s
end
office_from_details() click to toggle source

Returns detailed information about the origin post office, only if the {Tracker#check}/{Tracker#check_many} method was called with details set to true. @return [Office]

# 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_to() click to toggle source

@return [String] destination post office name

# File lib/poczta_polska/package.rb, line 53
def office_to
  @data[:dane_przesylki][:urzad_przezn][:nazwa].to_s
end
office_to_details() click to toggle source

Returns detailed information about the destination post office, only if the {Tracker#check}/{Tracker#check_many} method was called with details set to true. @return [Office]

# 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?() click to toggle source

@return [Boolean] whether the service has been finished (delivered, received in the post office, etc.)

# File lib/poczta_polska/package.rb, line 63
def ready?
  @data[:dane_przesylki][:zakonczono_obsluge]
end
type() click to toggle source

@return [Symbol] package type code

# File lib/poczta_polska/package.rb, line 18
def type
  @data[:dane_przesylki][:kod_rodz_przes].to_sym
end
type_str() click to toggle source

@return [String] human-readable package type

# File lib/poczta_polska/package.rb, line 23
def type_str
  @data[:dane_przesylki][:rodz_przes].to_s
end