Class: Edi::Wayfair::RecordCatalogParentCoverage::Coverage

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/wayfair/record_catalog_parent_coverage/coverage.rb

Overview

Maps every product from a verified scan to its local catalog item and
accumulates all distinct WRM parent codes for that supplier identifier.

Constant Summary collapse

PRODUCT_CODE_REGEXP =

Extracts a parent product code (e.g. W12345) from a Wayfair PDP URL.

/-([A-Za-z]+\d{3,})\.html/i
PARENT_CODE_REGEXP =

Matches a bare parent product code (W12345 / C12345).

/\A[A-Za-z]+\d{3,}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catalog:, products:) ⇒ Coverage

Returns a new instance of Coverage.

Parameters:

  • catalog (Catalog)

    the Wayfair catalog being re-covered

  • products (Array<Hash>)

    supplierCatalog products from a verified Scan



15
16
17
18
19
20
21
22
23
# File 'app/services/edi/wayfair/record_catalog_parent_coverage/coverage.rb', line 15

def initialize(catalog:, products:)
  @catalog_items = catalog.catalog_items
                          .where(state: 'active')
                          .includes(store_item: :item)
                          .to_a
  @coverage = Hash.new { |hash, catalog_item_id| hash[catalog_item_id] = [] }
  @errors = []
  products.each { |product| add(product) }
end

Instance Attribute Details

#catalog_itemsObject (readonly)

Returns the value of attribute catalog_items.



11
12
13
# File 'app/services/edi/wayfair/record_catalog_parent_coverage/coverage.rb', line 11

def catalog_items
  @catalog_items
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'app/services/edi/wayfair/record_catalog_parent_coverage/coverage.rb', line 11

def errors
  @errors
end

Instance Method Details

#for(catalog_item) ⇒ Array<String>

Parameters:

Returns:

  • (Array<String>)


27
28
29
# File 'app/services/edi/wayfair/record_catalog_parent_coverage/coverage.rb', line 27

def for(catalog_item)
  @coverage.fetch(catalog_item.id, []).compact_blank.map(&:upcase).uniq.sort
end