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


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

def graphic_extension
  @graphic_extension
end

#graphic_imageObject

Returns the value of attribute graphic_image


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

def graphic_image
  @graphic_image
end

#html_imageObject

Returns the value of attribute html_image


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

def html_image
  @html_image
end

#tracking_numberObject

Returns the value of attribute tracking_number


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

def tracking_number
  @tracking_number
end

Instance Method Details

#base64_to_file(contents) ⇒ Object


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

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


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

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

#parse_graphic_image(value) ⇒ Object


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

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


27
28
29
30
# File 'lib/ups/parsers/ship_accept_parser.rb', line 27

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


32
33
34
35
# File 'lib/ups/parsers/ship_accept_parser.rb', line 32

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

#value(value) ⇒ Object


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

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