Class: EndiciaLabelServer::Parsers::ParserBase

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParserBase

Returns a new instance of ParserBase.



11
12
13
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 11

def initialize
  self.switches = {}
end

Instance Attribute Details

#error_descriptionObject

Returns the value of attribute error_description.



7
8
9
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 7

def error_description
  @error_description
end

#status_codeObject

Returns the value of attribute status_code.



7
8
9
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 7

def status_code
  @status_code
end

#switchesObject

Returns the value of attribute switches.



7
8
9
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 7

def switches
  @switches
end

Instance Method Details

#element_tracker_switch(element, currently_in) ⇒ Object



29
30
31
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 29

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

#end_element(name) ⇒ Object



19
20
21
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 19

def end_element(name)
  element_tracker_switch name, false
end

#start_element(name) ⇒ Object



15
16
17
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 15

def start_element(name)
  element_tracker_switch name, true
end

#success?Boolean

Returns:

  • (Boolean)


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

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

#switch_active?(*elements) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 33

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

#value(value) ⇒ Object



23
24
25
26
27
# File 'lib/endicia_label_server/parsers/parser_base.rb', line 23

def value(value)
  string_value = value.as_s
  self.status_code = string_value if switch_active? :Status
  self.error_description = string_value if switch_active? :ErrorMessage
end