feat: add StationTaggingService with supermarket detection
This commit is contained in:
32
app/Services/StationTaggingService.php
Normal file
32
app/Services/StationTaggingService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Station;
|
||||
|
||||
class StationTaggingService
|
||||
{
|
||||
/** @var array<string, string> brand keyword → normalised brand name */
|
||||
private const SUPERMARKET_BRANDS = [
|
||||
'tesco' => 'Tesco',
|
||||
'asda' => 'Asda',
|
||||
'morrisons' => 'Morrisons',
|
||||
'sainsbury' => 'Sainsbury\'s',
|
||||
'aldi' => 'Aldi',
|
||||
'lidl' => 'Lidl',
|
||||
'costco' => 'Costco',
|
||||
];
|
||||
|
||||
public function tag(Station $station): void
|
||||
{
|
||||
$name = strtolower($station->trading_name);
|
||||
|
||||
foreach (self::SUPERMARKET_BRANDS as $keyword => $normalisedBrand) {
|
||||
if (str_contains($name, $keyword)) {
|
||||
$station->is_supermarket = true;
|
||||
$station->brand_name = $normalisedBrand;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user