Class: Edi::Wayfair::RecordCatalogParentCoverage::Coverage
- Inherits:
-
Object
- Object
- Edi::Wayfair::RecordCatalogParentCoverage::Coverage
- 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
-
#catalog_items ⇒ Object
readonly
Returns the value of attribute catalog_items.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #for(catalog_item) ⇒ Array<String>
-
#initialize(catalog:, products:) ⇒ Coverage
constructor
A new instance of Coverage.
Constructor Details
#initialize(catalog:, products:) ⇒ Coverage
Returns a new instance of Coverage.
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_items ⇒ Object (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 |
#errors ⇒ Object (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>
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 |