Class: PocztaPolska::Office
- Inherits:
-
Object
- Object
- PocztaPolska::Office
- Defined in:
- lib/poczta_polska/office.rb
Overview
The Office class stores detailed information about a particular post office.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Original data from the XML response.
Instance Method Summary collapse
-
#address ⇒ Hash
Returns the address of the post office.
-
#coordinates ⇒ Array(Float, Float)
Returns geographical coordinates of the post office.
-
#initialize(data) ⇒ Office
constructor
A new instance of Office.
-
#opening_hours ⇒ Hash<Symbol => Array(String, String), nil>
Returns opening hours of the post office.
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
#data ⇒ Hash (readonly)
Returns Original data from the XML response.
6 7 8 |
# File 'lib/poczta_polska/office.rb', line 6 def data @data end |
Instance Method Details
#address ⇒ Hash
Returns the address of the post office. The keys in the hash are :street
, :number
, :code
and :town
.
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 |
#coordinates ⇒ Array(Float, Float)
Returns geographical coordinates of the post office.
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_hours ⇒ Hash<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
.
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 |