Class: UPS::Parsers::TrackParser

Inherits:
BaseParser show all
Defined in:
lib/ups/parsers/track_parser.rb

Instance Attribute Summary

Attributes inherited from BaseParser

#response

Instance Method Summary collapse

Methods inherited from BaseParser

#error_description, #parsed_response, #status_code, #status_description, #success?

Constructor Details

#initialize(response) ⇒ TrackParser

Returns a new instance of TrackParser.



7
8
9
10
# 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

Instance Method Details

#activitiesObject



20
21
22
# File 'lib/ups/parsers/track_parser.rb', line 20

def activities
  normalize_response_into_array(root_response[:Shipment][:Package][:Activity])
end

#status_dateObject



24
25
26
# File 'lib/ups/parsers/track_parser.rb', line 24

def status_date
  Date.parse(latest_activity[:Date])
end

#status_type_codeObject



32
33
34
# File 'lib/ups/parsers/track_parser.rb', line 32

def status_type_code
  status_type[:Code]
end

#status_type_descriptionObject



28
29
30
# File 'lib/ups/parsers/track_parser.rb', line 28

def status_type_description
  status_type[:Description]
end

#to_hObject



12
13
14
15
16
17
18
# 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