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


10
11
12
# File 'lib/poczta_polska/event.rb', line 10

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataHash (readonly)


8
9
10
# File 'lib/poczta_polska/event.rb', line 8

def data
  @data
end

Instance Method Details

#codeSymbol


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

#nameString


25
26
27
# File 'lib/poczta_polska/event.rb', line 25

def name
  @data[:nazwa].to_s
end

#officeString


30
31
32
# File 'lib/poczta_polska/event.rb', line 30

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.


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

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


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

#timeDateTime


15
16
17
# File 'lib/poczta_polska/event.rb', line 15

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