Class: UPS::Parsers::RatesParser
Instance Attribute Summary collapse
Attributes inherited from ParserBase
#error_description, #status_code, #status_description, #switches
Instance Method Summary
collapse
Methods inherited from ParserBase
#build_switch_path, #element_tracker_switch, #success?, #switch_active?
Constructor Details
Returns a new instance of RatesParser.
6
7
8
9
10
|
# File 'lib/ups/parsers/rates_parser.rb', line 6
def initialize
super
self.rated_shipments = []
@current_rate = {}
end
|
Instance Attribute Details
#rated_shipments ⇒ Object
Returns the value of attribute rated_shipments.
4
5
6
|
# File 'lib/ups/parsers/rates_parser.rb', line 4
def rated_shipments
@rated_shipments
end
|
Instance Method Details
#end_element(name) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/ups/parsers/rates_parser.rb', line 16
def end_element(name)
super
return unless name == :RatedShipment
rated_shipments << @current_rate.tap do |c|
if c.key? :negotiated_rate
c[:total] = c[:negotiated_rate]
c.delete :negotiated_rate
end
end
@current_rate = {}
end
|
#parse_negotiated_rate(value) ⇒ Object
41
42
43
|
# File 'lib/ups/parsers/rates_parser.rb', line 41
def parse_negotiated_rate(value)
@current_rate[:negotiated_rate] = value.as_s
end
|
#parse_rated_shipment_warning(value) ⇒ Object
45
46
47
48
|
# File 'lib/ups/parsers/rates_parser.rb', line 45
def parse_rated_shipment_warning(value)
@current_rate[:warnings] ||= []
@current_rate[:warnings] << value.as_s
end
|
#parse_service_code(value) ⇒ Object
50
51
52
53
|
# File 'lib/ups/parsers/rates_parser.rb', line 50
def parse_service_code(value)
@current_rate[:service_code] = value.as_s
@current_rate[:service_name] = UPS::SERVICES[value.as_s]
end
|
#parse_total_charges(value) ⇒ Object
55
56
57
|
# File 'lib/ups/parsers/rates_parser.rb', line 55
def parse_total_charges(value)
@current_rate[:total] = value.as_s
end
|
#start_element(name) ⇒ Object
12
13
14
|
# File 'lib/ups/parsers/rates_parser.rb', line 12
def start_element(name)
super
end
|
#value(value) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ups/parsers/rates_parser.rb', line 28
def value(value)
super
if switch_active?(:RatedShipment, :Service, :Code)
parse_service_code value
elsif switch_active?(:RatedShipment, :TotalCharges)
parse_total_charges value
elsif switch_active?(:RatedShipment, :NegotiatedRates, :MonetaryValue)
parse_negotiated_rate value
elsif switch_active?(:RatedShipment, :RatedShipmentWarning)
parse_rated_shipment_warning value
end
end
|