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