Phoenix 1.8 app that scrapes ammunition retailers (Lucky Gunner, SGAmmo) for price data and displays historical price trends. - Data model: retailers, calibers, products, price snapshots - Scraper infrastructure with Req, Floki, realistic browser headers - Oban-scheduled scrape jobs (every 4h with randomized delays) - LiveView pages: homepage with category cards, caliber detail with price table, Chart.js price history, and price stats banner - 18 seeded calibers across handgun/rifle/rimfire/shotgun categories - 77 tests
21 lines
567 B
Elixir
21 lines
567 B
Elixir
defmodule Ammoprices.Scraping.CaliberMatcher do
|
|
@moduledoc false
|
|
|
|
def match(title, calibers) do
|
|
downcased = String.downcase(title)
|
|
|
|
Enum.find(calibers, fn caliber ->
|
|
name_matches?(downcased, caliber) or alias_matches?(downcased, caliber)
|
|
end)
|
|
end
|
|
|
|
defp name_matches?(downcased_title, caliber) do
|
|
String.contains?(downcased_title, String.downcase(caliber.name))
|
|
end
|
|
|
|
defp alias_matches?(downcased_title, caliber) do
|
|
Enum.any?(caliber.aliases, fn a ->
|
|
String.contains?(downcased_title, String.downcase(a))
|
|
end)
|
|
end
|
|
end
|