Class: Deliveries::CollectionPoint

Inherits:
Address
  • Object
show all
Defined in:
lib/deliveries/collection_point.rb

Constant Summary

Constants inherited from Address

Address::COUNTRY_PHONE_PREFIXES, Address::COUNTRY_TRUNK_PREFIXES

Instance Attribute Summary collapse

Attributes inherited from Address

#address_id, #city, #country, #email, #name, #phone, #postcode, #state, #street

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Address

#courierize

Constructor Details

#initialize(**attributes) ⇒ CollectionPoint

Returns a new instance of CollectionPoint.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/deliveries/collection_point.rb', line 6

def initialize(**attributes)
  super(**attributes)

  self.courier_id = attributes[:courier_id]
  self.point_id = attributes[:point_id]
  self.latitude = attributes[:latitude]
  self.longitude = attributes[:longitude]
  self.timetable = attributes[:timetable]
  self.url_map = attributes[:url_map]
  self.url_photo = attributes[:url_photo]
end

Instance Attribute Details

#courier_idObject

Returns the value of attribute courier_id.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def courier_id
  @courier_id
end

#latitudeObject

Returns the value of attribute latitude.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def longitude
  @longitude
end

#point_idObject

Returns the value of attribute point_id.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def point_id
  @point_id
end

#timetable(start_day: :monday) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deliveries/collection_point.rb', line 22

def timetable(start_day: :monday)
  raise Error, "Invalid week start day: #{start_day}" unless %i[monday sunday].include?(start_day)

  @timetable&.sort_by do |wday, _slots|
    if wday.zero? && start_day == :monday
      7
    else
      wday
    end
  end&.to_h
end

#url_mapObject

Returns the value of attribute url_map.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def url_map
  @url_map
end

#url_photoObject

Returns the value of attribute url_photo.



3
4
5
# File 'lib/deliveries/collection_point.rb', line 3

def url_photo
  @url_photo
end

Class Method Details

.parse_global_point_id(global_point_id:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/deliveries/collection_point.rb', line 34

def self.parse_global_point_id(global_point_id:)
  global_point = global_point_id.split('~')

  OpenStruct.new(
    courier_id: global_point[0],
    country: global_point[1],
    postcode: global_point[2],
    point_id: global_point[3]
  )
end

Instance Method Details

#global_point_idObject



18
19
20
# File 'lib/deliveries/collection_point.rb', line 18

def global_point_id
  "#{courier_id}~#{country}~#{postcode}~#{point_id}"
end