Class: PocztaPolska::Office

Inherits:
Object
  • Object
show all
Defined in:
lib/poczta_polska/office.rb

Overview

The Office class stores detailed information about a particular post office.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Office

Returns a new instance of Office.



8
9
10
# File 'lib/poczta_polska/office.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/office.rb', line 6

def data
  @data
end

Instance Method Details

#addressHash

Returns the address of the post office. The keys in the hash are :street, :number, :code and :town.

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
# File 'lib/poczta_polska/office.rb', line 21

def address
  {
    street: @data[:ulica].to_s,
    number: @data.values_at(:nr_domu, :nr_lokalu).compact.join('/'),
    code: @data[:pna].to_s,
    town: @data[:miejscowosc].to_s
  }
end

#coordinatesArray(Float, Float)

Returns geographical coordinates of the post office.

Returns:

  • (Array(Float, Float))

    latitude and longitude



14
15
16
# File 'lib/poczta_polska/office.rb', line 14

def coordinates
  [@data[:szer_geogr].to_f, @data[:dl_geogr].to_f]
end

#opening_hoursHash<Symbol => Array(String, String), nil>

Returns opening hours of the post office. The keys in the hash are :weekdays, :saturdays and :sundays (including holidays). Every value is an array in the format [opening_hours, notes] or nil.

Returns:

  • (Hash<Symbol => Array(String, String), nil>)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/poczta_polska/office.rb', line 34

def opening_hours
  hours = @data[:godziny_pracy]
  keys = {weekdays: :dni_robocze, saturdays: :soboty, sundays: :niedz_i_sw}
  Hash[
    keys.map do |h, x|
      value = unless hours[x].nil?
        [hours[x][:godziny].to_s, hours[x][:uwagi].to_s]
      end

      [h, value]
    end
  ]
end