class Deliveries::Couriers::MondialRelay::CollectionPoints::Search::FormatResponse

Constants

WEEKDAYS_STARTING_SUNDAY

Attributes

response[RW]

Public Class Methods

new(response:) click to toggle source
# File lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb, line 43
def initialize(response:)
  self.response = response
end

Public Instance Methods

execute() click to toggle source
# File lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb, line 47
def execute
  point = {}

  point[:courier_id] = 'mondial_relay'
  point[:point_id] = response[:num]
  point[:country] = response[:pays]
  point[:city] = response[:ville].strip unless response[:ville].nil?
  point[:postcode] = response[:cp].strip unless response[:cp].nil?
  point[:url_map] = response[:url_plan]
  point[:latitude] = response[:latitude].tr(',', '.').to_f
  point[:longitude] = response[:longitude].tr(',', '.').to_f
  point[:timetable] = formatted_timetable(response)
  point[:url_photo] = response[:url_photo]
  point[:name] = response[:lg_adr1].strip
  point[:street] = response[:lg_adr3].strip

  point
end

Private Instance Methods

formatted_slot(open:, close:) click to toggle source
# File lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb, line 95
def formatted_slot(open:, close:)
  OpenStruct.new(open: open.insert(2, ':'), close: close.insert(2, ':'))
end
formatted_timetable(result) click to toggle source
# File lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb, line 68
def formatted_timetable(result)
  timetable = {}

  week_hours = get_week_hours_from_result(result)
  week_hours.each do |i, times|
    timetable[i] = []
    if times[0] == '0000'
      timetable[i] << nil
    else
      timetable[i] << formatted_slot(open: times[0], close: times[1])
      timetable[i] << formatted_slot(open: times[2], close: times[3]) if times[2] != '0000'
    end
    timetable[i] = nil unless timetable[i].any?
  end

  timetable
end
get_week_hours_from_result(result) click to toggle source
# File lib/deliveries/couriers/mondial_relay/collection_points/search/format_response.rb, line 86
def get_week_hours_from_result(result)
  week_hours = {}
  WEEKDAYS_STARTING_SUNDAY.each_with_index do |day, i|
    week_hours[i] = result["horaires_#{day}".to_sym][:string]
  end

  week_hours
end