Class: Edi::Commercehub::PackingSlipReaderLowesCom
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Commercehub::PackingSlipReaderLowesCom
- Defined in:
- app/services/edi/commercehub/packing_slip_reader_lowes_com.rb
Constant Summary
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Instance Method Summary collapse
Methods inherited from BaseEdiService
#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log
Methods included from AddressAbbreviator
#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#process(file_path, _options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/edi/commercehub/packing_slip_reader_lowes_com.rb', line 6 def process(file_path, = {}) return unless File.exist?(file_path) identity = nil begin require 'pdf/inspector' ta = PDF::Inspector::Text.analyze(File.read(file_path)) # Get an array of all strings discovered strings = ta.strings # here we look for a string with 'PO Number:'' in it, ie this is how Lowe's US has it, see example below: # result of ta.strings: # ... # [N-2] "Customer Order Number:", # [N-2] "000001234", # [N] "PO Number:", # [N+1] "00003333", # ... # then we take the next string which has the actual PO number in it if the PO# string was found ind = strings.index{|s| s=~ /^PO Number:/} if ind identity = nil identity = strings[ind+1] else # looking at Lowe's 'cross-dock placard' ind = strings.index('P.O. #:') # this is for the Lowe's cross-dock placard' in case it is needed? identity = nil identity = strings[ind+6] if ind end rescue StandardError => exc logger.error "Unable to process file #{file_path}, #{exc}" ErrorReporting.error exc end identity end |