Class: PocztaPolska::Event

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataHash (readonly)

Returns Original data from the XML response.

Returns:

  • (Hash)

    Original data from the XML response



6
7
8
# File 'lib/poczta_polska/event.rb', line 6

def data
  @data
end

Instance Method Details

#codeSymbol

Returns code of the event.

Returns:

  • (Symbol)

    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.).

Returns:

  • (Boolean)

    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

#nameString

Returns human-readable name of the event.

Returns:

  • (String)

    human-readable name of the event



23
24
25
# File 'lib/poczta_polska/event.rb', line 23

def name
  @data[:nazwa].to_s
end

#officeString

Returns name of the post office.

Returns:

  • (String)

    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_detailsOffice

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.

Returns:



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

#reasonHash

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.

Returns:

  • (Hash)


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

#timeDateTime

Returns date and time of the event.

Returns:

  • (DateTime)

    date and time of the event



13
14
15
# File 'lib/poczta_polska/event.rb', line 13

def time
  DateTime.parse(@data[:czas])
end