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
11 12 13 |
# File 'lib/poczta_polska/package.rb', line 11 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Hash (readonly)
9 10 11 |
# File 'lib/poczta_polska/package.rb', line 9 def data @data end |
Instance Method Details
#country_from ⇒ Symbol
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_str ⇒ String
36 37 38 |
# File 'lib/poczta_polska/package.rb', line 36 def country_from_str @data[:dane_przesylki][:kraj_nadania].to_s end |
#country_to ⇒ Symbol
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_str ⇒ String
46 47 48 |
# File 'lib/poczta_polska/package.rb', line 46 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
90 91 92 |
# File 'lib/poczta_polska/package.rb', line 90 def events @data[:dane_przesylki][:zdarzenia][:zdarzenie].map { |e| Event.new(e) } end |
#id ⇒ String
16 17 18 |
# File 'lib/poczta_polska/package.rb', line 16 def id @data[:numer].to_s end |
#mass ⇒ Float
61 62 63 |
# File 'lib/poczta_polska/package.rb', line 61 def mass @data[:dane_przesylki][:masa] end |
#office_from ⇒ String
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_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
.
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_to ⇒ String
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_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
.
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
66 67 68 |
# File 'lib/poczta_polska/package.rb', line 66 def ready? @data[:dane_przesylki][:zakonczono_obsluge] end |
#type ⇒ Symbol
21 22 23 |
# File 'lib/poczta_polska/package.rb', line 21 def type @data[:dane_przesylki][:kod_rodz_przes].to_sym end |
#type_str ⇒ String
26 27 28 |
# File 'lib/poczta_polska/package.rb', line 26 def type_str @data[:dane_przesylki][:rodz_przes].to_s end |