Class: Portage::Cli::Compare

Inherits:
Find
  • Object
show all
Defined in:
lib/portage/cli/compare.rb

Overview

portage compare <url> --product-id ID — §22's "find this same item elsewhere" mode. Resolves a product a shopper already has in hand, then runs Find's own candidate-discovery/probe/rank pipeline against the product's own title, scoring each surviving offer by how confident we actually are that it's the same item rather than just a similarly titled one.

Catalog-price only: nothing here calls create_checkout against a candidate store, so a ranked offer's price is the listed price, never a landed price. See docs/plans/portage-compare.md for why that's a deliberate scope cut, not an oversight.

Constant Summary collapse

RESULT_LIMIT =
5
TIER_RANK =
{ confirmed: 0, likely: 1, unconfirmed: 2 }.freeze

Constants inherited from Find

Find::CART_CAP, Find::CHECKOUT_CAP, Find::MAX_PROBES, Find::PER_STORE_RESULTS, Find::THROTTLE

Instance Method Summary collapse

Constructor Details

#initialize(origin_url:, origin_product_id:, identity: [], results: RESULT_LIMIT, max_price: nil, find_options: {}) ⇒ Compare

identity: is one repeatable value, not four aliases (--mpn/--sku/ --upc/--gtin) for the same untyped string corpus — the wire format doesn't distinguish barcode types, so a flag name implying it could would be lying about the matcher's actual precision. find_options: bundles Find's own backends:/cache:/throttle: pass-through so this initializer stays under Metrics/ParameterLists without an exclusion.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/portage/cli/compare.rb', line 26

def initialize(origin_url:, origin_product_id:, identity: [], results: RESULT_LIMIT, max_price: nil,
               find_options: {})
  @origin_url = origin_url
  @origin_product_id = origin_product_id
  @explicit_identity = identity
  @result_limit = results
  # `query: nil` — the real query isn't known until #call resolves the
  # origin product; Find reads @query at #call time, not construction
  # time, so #call can overwrite it before invoking Find#call via super.
  super(query: nil, max_price: max_price, **find_options)
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/portage/cli/compare.rb', line 38

def call
  origin = resolve_origin
  return origin if origin[:message]

  @origin_host = origin[:host]
  @identity = build_identity(origin[:product])
  @query = origin[:title]
  result = super
  finish(result)
end