Class: PocztaPolska::Event
- Inherits:
-
Object
- Object
- PocztaPolska::Event
- Defined in:
- lib/poczta_polska/event.rb
Overview
The Event class stores information about a point on the package’s way.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Original data from the XML response.
Instance Method Summary collapse
-
#code ⇒ Symbol
Code of the event.
-
#final? ⇒ Boolean
Whether this is the final event (delivery, receiving in the post office, etc.).
-
#initialize(data) ⇒ Event
constructor
A new instance of Event.
-
#name ⇒ String
Human-readable name of the event.
-
#office ⇒ String
Name of the post office.
-
#office_details ⇒ Office
Returns detailed information about the post office connected with this event, only if the Tracker#check/Tracker#check_many method was called with
details
set totrue
. -
#reason ⇒ Hash
Returns a reason of the event (available only for certain events and certain users) or
nil
. -
#time ⇒ DateTime
Date and time of the event.
Constructor Details
#initialize(data) ⇒ Event
Returns a new instance of Event.
8 9 10 |
# File 'lib/poczta_polska/event.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/event.rb', line 6 def data @data end |
Instance Method Details
#code ⇒ Symbol
Returns code of the event.
18 19 20 |
# File 'lib/poczta_polska/event.rb', line 18 def code @data[:kod].to_sym end |
#final? ⇒ Boolean
Returns whether this is the final event (delivery, receiving in the post office, etc.).
33 34 35 |
# File 'lib/poczta_polska/event.rb', line 33 def final? @data[:konczace] end |
#name ⇒ String
Returns human-readable name of the event.
23 24 25 |
# File 'lib/poczta_polska/event.rb', line 23 def name @data[:nazwa].to_s end |
#office ⇒ String
Returns name of the post office.
28 29 30 |
# File 'lib/poczta_polska/event.rb', line 28 def office @data[:jednostka][:nazwa].to_s end |
#office_details ⇒ Office
Returns detailed information about the post office connected with this event, only if the Tracker#check/Tracker#check_many method was called with details
set to true
.
41 42 43 44 |
# File 'lib/poczta_polska/event.rb', line 41 def office_details office = @data[:jednostka][:dane_szczegolowe] Office.new(office) unless office.nil? end |
#reason ⇒ Hash
Returns a reason of the event (available only for certain events and certain users) or nil
. The keys in the hash are :code
and :name
.
49 50 51 52 53 54 |
# File 'lib/poczta_polska/event.rb', line 49 def reason { code: @data[:przyczyna][:kod].to_sym, name: @data[:przyczyna][:nazwa].to_s } unless @data[:przyczyna].nil? end |
#time ⇒ DateTime
Returns date and time of the event.
13 14 15 |
# File 'lib/poczta_polska/event.rb', line 13 def time DateTime.parse(@data[:czas]) end |