Class: PocztaPolska::Package
- Inherits:
-
Object
- Object
- PocztaPolska::Package
- Defined in:
- lib/poczta_polska/package.rb
Overview
The Package class contains all necessary information about a tracked package.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Original data from the XML response.
Instance Method Summary collapse
-
#country_from ⇒ Symbol
Origin country code.
-
#country_from_str ⇒ String
Origin country name.
-
#country_to ⇒ Symbol
Destination country code.
-
#country_to_str ⇒ String
Destination country name.
-
#events ⇒ Array<Event>
Returns a list of all events connected with the package.
-
#id ⇒ String
Package ID.
-
#initialize(data) ⇒ Package
constructor
A new instance of Package.
-
#mass ⇒ Float
Mass of the package.
-
#office_from ⇒ String
Origin post office name.
-
#office_from_details ⇒ Office
Returns detailed information about the origin post office, only if the Tracker#check/Tracker#check_many method was called with
details
set totrue
. -
#office_to ⇒ String
Destination post office name.
-
#office_to_details ⇒ Office
Returns detailed information about the destination post office, only if the Tracker#check/Tracker#check_many method was called with
details
set totrue
. -
#ready? ⇒ Boolean
Whether the service has been finished (delivered, received in the post office, etc.).
-
#type ⇒ Symbol
Package type code.
-
#type_str ⇒ String
Human-readable package type.
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
#data ⇒ Hash (readonly)
Returns 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_from ⇒ Symbol
Returns 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_str ⇒ String
Returns 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_to ⇒ Symbol
Returns 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_str ⇒ String
Returns 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 |
#events ⇒ Array<Event>
Returns a list of all events connected with the package
87 88 89 |
# File 'lib/poczta_polska/package.rb', line 87 def events @data[:dane_przesylki][:zdarzenia][:zdarzenie]&.map { |e| Event.new(e) } || [] end |
#id ⇒ String
Returns package ID.
13 14 15 |
# File 'lib/poczta_polska/package.rb', line 13 def id @data[:numer].to_s end |
#mass ⇒ Float
Returns mass of the package.
58 59 60 |
# File 'lib/poczta_polska/package.rb', line 58 def mass @data[:dane_przesylki][:masa] end |
#office_from ⇒ String
Returns 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_details ⇒ Office
Returns detailed information about the origin post office, only if the Tracker#check/Tracker#check_many method was called with details
set to true
.
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_to ⇒ String
Returns 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_details ⇒ Office
Returns detailed information about the destination post office, only if the Tracker#check/Tracker#check_many method was called with details
set to true
.
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.).
63 64 65 |
# File 'lib/poczta_polska/package.rb', line 63 def ready? @data[:dane_przesylki][:zakonczono_obsluge] end |
#type ⇒ Symbol
Returns 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_str ⇒ String
Returns 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 |