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
10 11 12 |
# File 'lib/poczta_polska/event.rb', line 10 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Hash (readonly)
8 9 10 |
# File 'lib/poczta_polska/event.rb', line 8 def data @data end |
Instance Method Details
#code ⇒ Symbol
20 21 22 |
# File 'lib/poczta_polska/event.rb', line 20 def code @data[:kod].to_sym end |
#final? ⇒ Boolean
35 36 37 |
# File 'lib/poczta_polska/event.rb', line 35 def final? @data[:konczace] end |
#name ⇒ String
25 26 27 |
# File 'lib/poczta_polska/event.rb', line 25 def name @data[:nazwa].to_s end |
#office ⇒ String
30 31 32 |
# File 'lib/poczta_polska/event.rb', line 30 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
.
43 44 45 46 |
# File 'lib/poczta_polska/event.rb', line 43 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
.
51 52 53 54 55 56 |
# File 'lib/poczta_polska/event.rb', line 51 def reason { code: @data[:przyczyna][:kod].to_sym, name: @data[:przyczyna][:nazwa].to_s } unless @data[:przyczyna].nil? end |
#time ⇒ DateTime
15 16 17 |
# File 'lib/poczta_polska/event.rb', line 15 def time DateTime.parse(@data[:czas]) end |