Class: EndiciaLabelServer::Parsers::PostageLabelParser

Inherits:
ParserBase
  • Object
show all
Defined in:
lib/endicia_label_server/parsers/postage_label_parser.rb

Instance Attribute Summary collapse

Attributes inherited from ParserBase

#error_description, #status_code, #switches

Instance Method Summary collapse

Methods inherited from ParserBase

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

Constructor Details

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

Instance Attribute Details

#cost_centerObject

Returns the value of attribute cost_center


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def cost_center
  @cost_center
end

#final_postageObject

Returns the value of attribute final_postage


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def final_postage
  @final_postage
end

#labelObject

Returns the value of attribute label


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def label
  @label
end

#picObject

Returns the value of attribute pic


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def pic
  @pic
end

#postage_balanceObject

Returns the value of attribute postage_balance


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def postage_balance
  @postage_balance
end

#postmark_dateObject

Returns the value of attribute postmark_date


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def postmark_date
  @postmark_date
end

#requester_idObject

Returns the value of attribute requester_id


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def requester_id
  @requester_id
end

#tracking_numberObject

Returns the value of attribute tracking_number


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def tracking_number
  @tracking_number
end

#transaction_date_timeObject

Returns the value of attribute transaction_date_time


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def transaction_date_time
  @transaction_date_time
end

#transaction_idObject

Returns the value of attribute transaction_id


6
7
8
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 6

def transaction_id
  @transaction_id
end

Instance Method Details

#parse_label(encoded_label) ⇒ Object


43
44
45
46
47
48
49
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 43

def parse_label(encoded_label)
  label_file = Tempfile.new(['endicia', '.png'])
  label_file.binmode
  label_file.write(Base64.decode64(encoded_label))
  label_file.rewind
  self.label = label_file
end

#start_element(name) ⇒ Object


17
18
19
20
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 17

def start_element(name)
  super
  @current_element = name.to_s
end

#underscore(value) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 35

def underscore(value)
  value.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    tr('-', '_').
    downcase
end

#value(value) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/endicia_label_server/parsers/postage_label_parser.rb', line 22

def value(value)
  super

  element = underscore(@current_element)
  string_value = value.as_s
  if switch_active? :Base64LabelImage
    parse_label(string_value)
  else
    function_name = "#{element}="
    send(function_name, string_value) if respond_to?(function_name)
  end
end