Class: Edi::Commercehub::PackingSlipReaderLowesCa

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/commercehub/packing_slip_reader_lowes_ca.rb

Constant Summary

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

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



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
39
40
41
42
43
# File 'app/services/edi/commercehub/packing_slip_reader_lowes_ca.rb', line 7

def process(file_path, _options = {})
  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# in it, ie this is how Lowe's has it, see example below:
    # result of ta.strings:
    # ...
    # [64] "Pour plus d'information sur les retours et les remboursements, contactez le service",
    # [65] "à la clientèle.",
    # [66] "PO#: /N° de BC :",
    # [67] "LLP-004916",
    # [68] "If you ordered more than the above-shown item(s), the rest of your items will be",
    # ...
    # 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#/}
    identity = nil
    identity = strings[ind+1] if ind
    # Otherwise proceed with previous algorithm for Reno, Rona
    # Find the position of the PO # label
    identity ||= strings.detect { |s| s =~ /^PO[A-Z]{4,}\_[0-9]{7,}$/ }
    # Reno PO# begin with Reno_ followed by numbers
    identity ||= strings.detect{|s| s =~ /^Reno_\d+/}
    # Rona PO# begin with Rona_4138
    identity ||= strings.detect{|s| s =~ /^Rona_\d+/}
    # Lowes PO# begin with LLP-
    identity ||= strings.detect { |s| s =~ /^LLP-[0-9]{6,}$/ }
  rescue StandardError => exc
    logger.error "Unable to process file #{file_path}, #{exc}"
    ErrorReporting.error exc
  end
  identity
end