Class: UPS::Parsers::ParserBase

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/ups/parsers/parser_base.rb

Direct Known Subclasses

RatesParser, ShipAcceptParser, ShipConfirmParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParserBase

Returns a new instance of ParserBase.


14
15
16
# File 'lib/ups/parsers/parser_base.rb', line 14

def initialize
  self.switches = {}
end

Instance Attribute Details

#error_descriptionObject

Returns the value of attribute error_description


9
10
11
# File 'lib/ups/parsers/parser_base.rb', line 9

def error_description
  @error_description
end

#status_codeObject

Returns the value of attribute status_code


9
10
11
# File 'lib/ups/parsers/parser_base.rb', line 9

def status_code
  @status_code
end

#status_descriptionObject

Returns the value of attribute status_description


9
10
11
# File 'lib/ups/parsers/parser_base.rb', line 9

def status_description
  @status_description
end

#switchesObject

Returns the value of attribute switches


9
10
11
# File 'lib/ups/parsers/parser_base.rb', line 9

def switches
  @switches
end

Instance Method Details

#element_tracker_switch(element, currently_in) ⇒ Object


37
38
39
# File 'lib/ups/parsers/parser_base.rb', line 37

def element_tracker_switch(element, currently_in)
  switches[element] = currently_in
end

#end_element(name) ⇒ Object


22
23
24
# File 'lib/ups/parsers/parser_base.rb', line 22

def end_element(name)
  element_tracker_switch name, false
end

#start_element(name) ⇒ Object


18
19
20
# File 'lib/ups/parsers/parser_base.rb', line 18

def start_element(name)
  element_tracker_switch name, true
end

#success?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/ups/parsers/parser_base.rb', line 45

def success?
  ['1', 1].include? status_code
end

#switch_active?(*elements) ⇒ Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/ups/parsers/parser_base.rb', line 41

def switch_active?(*elements)
  elements.all? { |element| switches[element] == true }
end

#value(value) ⇒ Object


26
27
28
29
30
31
32
33
34
35
# File 'lib/ups/parsers/parser_base.rb', line 26

def value(value)
  data = value.as_s
  self.status_code = data if switch_active? :ResponseStatusCode

  if switch_active?(:ResponseStatusDescription)
    self.status_description = data
  end

  self.error_description = data if switch_active? :ErrorDescription
end