Class: UPS::Parsers::ShipAcceptParser

Inherits:
ParserBase
  • Object
show all
Defined in:
lib/ups/parsers/ship_accept_parser.rb

Instance Attribute Summary collapse

Attributes inherited from ParserBase

#error_description, #status_code, #status_description, #switches

Instance Method Summary collapse

Methods inherited from ParserBase

#element_tracker_switch, #end_element, #initialize, #start_element, #success?, #switch_active?

Constructor Details

This class inherits a constructor from UPS::Parsers::ParserBase

Instance Attribute Details

#graphic_extensionObject

Returns the value of attribute graphic_extension.



7
8
9
# File 'lib/ups/parsers/ship_accept_parser.rb', line 7

def graphic_extension
  @graphic_extension
end

#graphic_imageObject

Returns the value of attribute graphic_image.



7
8
9
# File 'lib/ups/parsers/ship_accept_parser.rb', line 7

def graphic_image
  @graphic_image
end

#html_imageObject

Returns the value of attribute html_image.



7
8
9
# File 'lib/ups/parsers/ship_accept_parser.rb', line 7

def html_image
  @html_image
end

#tracking_numberObject

Returns the value of attribute tracking_number.



7
8
9
# File 'lib/ups/parsers/ship_accept_parser.rb', line 7

def tracking_number
  @tracking_number
end

Instance Method Details

#base64_to_file(contents) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/ups/parsers/ship_accept_parser.rb', line 40

def base64_to_file(contents)
  file_config = ['ups', graphic_extension]
  Tempfile.new(file_config, nil, encoding: 'ascii-8bit').tap do |file|
    begin
      file.write Base64.decode64(contents)
    ensure
      file.rewind
    end
  end
end

#parse_graphic_extension(value) ⇒ Object



35
36
37
38
# File 'lib/ups/parsers/ship_accept_parser.rb', line 35

def parse_graphic_extension(value)
  return unless switch_active?(:LabelImageFormat, :Code)
  self.graphic_extension = ".#{value.as_s.downcase}"
end

#parse_graphic_image(value) ⇒ Object



20
21
22
23
# File 'lib/ups/parsers/ship_accept_parser.rb', line 20

def parse_graphic_image(value)
  return unless switch_active?(:GraphicImage)
  self.graphic_image = base64_to_file(value.as_s)
end

#parse_html_image(value) ⇒ Object



25
26
27
28
# File 'lib/ups/parsers/ship_accept_parser.rb', line 25

def parse_html_image(value)
  return unless switch_active?(:HTMLImage)
  self.html_image = base64_to_file(value.as_s)
end

#parse_tracking_number(value) ⇒ Object



30
31
32
33
# File 'lib/ups/parsers/ship_accept_parser.rb', line 30

def parse_tracking_number(value)
  return unless switch_active?(:ShipmentIdentificationNumber)
  self.tracking_number = value.as_s
end

#value(value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ups/parsers/ship_accept_parser.rb', line 12

def value(value)
  parse_graphic_image(value)
  parse_html_image(value)
  parse_tracking_number(value)
  parse_graphic_extension(value)
  super
end