Skip to content

Commit

Permalink
Acronyms!
Browse files Browse the repository at this point in the history
  • Loading branch information
othyn committed Feb 4, 2024
1 parent 907e211 commit 8b5dda3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Entities/CalendarManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function create(LeekDuckEventType $eventType): self
eventType: $eventType,
calendar: Calendar::create()
->name(
name: 'GO Calendar - ' . $eventType->title
name: 'GO Calendar - ' . $eventType->title . ($eventType->title == CalendarService::EVERYTHING_CALENDAR_NAME ? '' : ' (' . acronymForEventType($eventType) . ')')
)
->description(
description: 'All Pokémon GO ' . ($eventType->title == CalendarService::EVERYTHING_CALENDAR_NAME ? '' : "{$eventType->title} ") . 'events, in your local time, auto-updated and sourced from Leek Duck.'
Expand Down
12 changes: 7 additions & 5 deletions src/Entities/LeekDuckEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ public static function create(array $event, string $timezone = CalendarService::
date: $endDate
);

$eventType = LeekDuckEventType::create(
name: $event['eventType'],
heading: $event['heading']
);

return new self(
eventId: $event['eventID'],
name: $event['name'],
title: "[{$event['heading']}] {$event['name']}",
title: '[' . acronymForEventType($eventType) . "] {$event['name']}",
description: 'Starts at ' . $startDate->format(format: 'H:i') . ', ends at ' . $endDate->format(format: 'H:i') . ".\n\n{$event['link']}",
type: LeekDuckEventType::create(
name: $event['eventType'],
heading: $event['heading']
),
type: $eventType,
link: $event['link'],
imageUrl: $event['image'],
startDateString: $event['start'],
Expand Down
36 changes: 36 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,46 @@

declare(strict_types=1);

use Console\Entities\LeekDuckEventType;

if (! function_exists(function: 'dd')) {
function dd(mixed $var): void
{
var_dump($var);
exit;
}
}

// https://laravel-news.com/laravel-str-acronym
if (! function_exists(function: 'acronym')) {
function acronym(string $string, $delimiter = ''): string
{
if (empty($string)) {
return '';
}

$acronym = '';

foreach (preg_split('/[^\p{L}]+/u', $string) as $word) {
if (!empty($word)) {
$first_letter = mb_substr($word, 0, 1);
$acronym .= $first_letter . $delimiter;
}
}

return $acronym;
}
}

if (! function_exists(function: 'acronymForEventType')) {
function acronymForEventType(LeekDuckEventType $eventType): string
{
// Otherwise it clashes with Raid Battles (RB)
return acronym(
string: $eventType->title == 'Research Breakthrough'
? 'Research Break Through'
: $eventType->title,
delimiter: ''
);
}
}

0 comments on commit 8b5dda3

Please sign in to comment.