239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/active_shipping/carriers/usps.rb', line 239
def (node)
description = node.at('Event').text.upcase
if prefix = ONLY_PREFIX_EVENTS.find { |p| description.start_with?(p) }
description = prefix
end
time = if node.at('EventDate').text.present?
timestamp = "#{node.at('EventDate').text}, #{node.at('EventTime').text}"
Time.parse(timestamp)
else
Time.at(0)
end
event_code = node.at('EventCode').text
city = node.at('EventCity').try(:text)
state = node.at('EventState').try(:text)
zip_code = node.at('EventZIPCode').try(:text)
country_node = node.at('EventCountry')
country = country_node ? country_node.text : ''
country = 'UNITED STATES' if country.empty?
country = find_country_code_case_insensitive(country)
zoneless_time = Time.utc(time.year, time.month, time.mday, time.hour, time.min, time.sec)
location = Location.new(city: city, state: state, postal_code: zip_code, country: country)
EventDetails.new(description, time, zoneless_time, location, event_code)
end
|