Class: EndiciaLabelServer::Parsers::PostageRateParser

Inherits:
ParserBase
  • Object
show all
Defined in:
lib/endicia_label_server/parsers/postage_rate_parser.rb

Direct Known Subclasses

PostageRatesParser

Instance Attribute Summary collapse

Attributes inherited from ParserBase

#error_description, #status_code, #switches

Instance Method Summary collapse

Methods inherited from ParserBase

#element_tracker_switch, #success?, #switch_active?

Constructor Details

#initializePostageRateParser

Returns a new instance of PostageRateParser.


6
7
8
9
10
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 6

def initialize
  super
  self.rated_shipments = []
  @current_rate = {}
end

Instance Attribute Details

#rated_shipmentsObject

Returns the value of attribute rated_shipments


4
5
6
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 4

def rated_shipments
  @rated_shipments
end

Instance Method Details

#end_element(name) ⇒ Object


16
17
18
19
20
21
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 16

def end_element(name)
  super
  return unless name == :Postage
  rated_shipments << @current_rate
  @current_rate = {}
end

#parse_mail_service(value) ⇒ Object


32
33
34
35
36
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 32

def parse_mail_service(value)
  service_code = EndiciaLabelServer::SERVICES.invert[value.as_s]
  @current_rate[:service_code] = service_code
  @current_rate[:service_name] = value.as_s
end

#parse_total_charges(value) ⇒ Object


38
39
40
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 38

def parse_total_charges(value)
  @current_rate[:total] = value.as_s
end

#start_element(name) ⇒ Object


12
13
14
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 12

def start_element(name)
  super
end

#value(value) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/endicia_label_server/parsers/postage_rate_parser.rb', line 23

def value(value)
  super
  if switch_active?(:Postage, :MailService)
    parse_mail_service value
  elsif switch_active?(:Postage, :Rate)
    parse_total_charges value
  end
end