class Deliveries::CollectionPoint

Attributes

courier_id[RW]
latitude[RW]
longitude[RW]
point_id[RW]
timetable[W]
url_map[RW]
url_photo[RW]

Public Class Methods

new(**attributes) click to toggle source
Calls superclass method Deliveries::Address::new
# 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
parse_global_point_id(global_point_id:) click to toggle source
# 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

Public Instance Methods

global_point_id() click to toggle source
# File lib/deliveries/collection_point.rb, line 18
def global_point_id
  "#{courier_id}~#{country}~#{postcode}~#{point_id}"
end
timetable(start_day: :monday) click to toggle source
# 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