class Deliveries::Couriers::CorreosExpress::CollectionPoints::Search::FormatResponse
Constants
- HOLIDAY_HOUR_KEY
- SATURDAY_HOUR_KEY
- WORKDAY_HOUR_KEY
Attributes
response[RW]
Public Class Methods
new(response:)
click to toggle source
# File lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb, line 22 def initialize(response:) self.response = response end
Public Instance Methods
execute()
click to toggle source
# File lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb, line 26 def execute collection_point = {} collection_point[:courier_id] = 'correos_express' collection_point[:name] = response['nombreOficina'] collection_point[:point_id] = response['codigoOficina'] collection_point[:street] = response['direccionOficina'] collection_point[:city] = response['poblacionOficina'] collection_point[:postcode] = response['codigoPostalOficina'] latitude, longitude = response['geoposicionOficina'].split(',') collection_point[:latitude] = latitude.to_f collection_point[:longitude] = longitude.to_f collection_point[:timetable] = formatted_timetable(response['horarioOficina']) collection_point end
Private Instance Methods
formatted_slot(hour, key)
click to toggle source
# File lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb, line 72 def formatted_slot(hour, key) open, close = hour.sub(key, '').sub('DE ', '').split(' A ') OpenStruct.new(open: open, close: close) end
formatted_timetable(params)
click to toggle source
# File lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb, line 44 def formatted_timetable(params) workday_hour, saturday_hour, holiday_hour = get_week_hours_from_result(params) timetable = {} if workday_hour.present? 1.upto(5) do |weekday| timetable[weekday] = [formatted_slot(workday_hour, WORKDAY_HOUR_KEY)] end end timetable[6] = [formatted_slot(saturday_hour, SATURDAY_HOUR_KEY)] if saturday_hour.present? timetable[0] = nil if holiday_hour.present? timetable end
get_week_hours_from_result(params)
click to toggle source
# File lib/deliveries/couriers/correos_express/collection_points/search/format_response.rb, line 62 def get_week_hours_from_result(params) week_hours = params.split('/') workday_hour = week_hours.select { |o| o.start_with?(WORKDAY_HOUR_KEY) }.first saturday_hour = week_hours.select { |o| o.start_with?(SATURDAY_HOUR_KEY) }.first holiday_hour = week_hours.select { |o| o.start_with?(HOLIDAY_HOUR_KEY) }.first [workday_hour, saturday_hour, holiday_hour] end