class UPS::Parsers::TrackParser

Public Class Methods

new(response) click to toggle source
Calls superclass method UPS::Parsers::BaseParser::new
# File lib/ups/parsers/track_parser.rb, line 7
def initialize(response)
  # Unescape double/triple quoted first line: "<?xml version=\\\"1.0\\\"?>\\n<TrackResponse>\n"
  super(response.gsub(/\\"/, '"').gsub(/\\n/, "\n"))
end

Public Instance Methods

activities() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 20
def activities
  normalize_response_into_array(root_response[:Shipment][:Package][:Activity])
end
status_date() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 24
def status_date
  Date.parse(latest_activity[:Date])
end
status_type_code() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 32
def status_type_code
  status_type[:Code]
end
status_type_description() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 28
def status_type_description
  status_type[:Description]
end
to_h() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 12
def to_h
  {
    status_date: status_date,
    status_type_description: status_type_description,
    status_type_code: status_type_code
  }
end

Private Instance Methods

latest_activity() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 42
def latest_activity
  activities.sort_by {|a| [a[:GMTDate], a[:GMTTime]] }.last
end
root_response() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 46
def root_response
  parsed_response[:TrackResponse]
end
status_type() click to toggle source
# File lib/ups/parsers/track_parser.rb, line 38
def status_type
  latest_activity[:Status][:StatusType]
end