Class: UPS::Parsers::ParserBase
- Inherits:
-
Ox::Sax
- Object
- Ox::Sax
- UPS::Parsers::ParserBase
show all
- Defined in:
- lib/ups/parsers/parser_base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ParserBase.
12
13
14
|
# File 'lib/ups/parsers/parser_base.rb', line 12
def initialize
self.switches = {}
end
|
Instance Attribute Details
#error_description ⇒ Object
Returns the value of attribute error_description.
7
8
9
|
# File 'lib/ups/parsers/parser_base.rb', line 7
def error_description
@error_description
end
|
#status_code ⇒ Object
Returns the value of attribute status_code.
7
8
9
|
# File 'lib/ups/parsers/parser_base.rb', line 7
def status_code
@status_code
end
|
#status_description ⇒ Object
Returns the value of attribute status_description.
7
8
9
|
# File 'lib/ups/parsers/parser_base.rb', line 7
def status_description
@status_description
end
|
#switches ⇒ Object
Returns the value of attribute switches.
7
8
9
|
# File 'lib/ups/parsers/parser_base.rb', line 7
def switches
@switches
end
|
Instance Method Details
#build_switch_path(*paths) ⇒ Object
43
44
45
|
# File 'lib/ups/parsers/parser_base.rb', line 43
def build_switch_path(*paths)
paths.flatten
end
|
#element_tracker_switch(element, currently_in) ⇒ Object
35
36
37
|
# File 'lib/ups/parsers/parser_base.rb', line 35
def element_tracker_switch(element, currently_in)
switches[element] = currently_in
end
|
#end_element(name) ⇒ Object
20
21
22
|
# File 'lib/ups/parsers/parser_base.rb', line 20
def end_element(name)
element_tracker_switch name, false
end
|
#start_element(name) ⇒ Object
16
17
18
|
# File 'lib/ups/parsers/parser_base.rb', line 16
def start_element(name)
element_tracker_switch name, true
end
|
#success? ⇒ Boolean
47
48
49
|
# File 'lib/ups/parsers/parser_base.rb', line 47
def success?
['1', 1].include? status_code
end
|
#switch_active?(*elements) ⇒ Boolean
39
40
41
|
# File 'lib/ups/parsers/parser_base.rb', line 39
def switch_active?(*elements)
elements.flatten.all? { |element| switches[element] == true }
end
|
#value(value) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/ups/parsers/parser_base.rb', line 24
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
|