Skip to content

Commit

Permalink
Driver name shortening improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mauserrifle committed Dec 5, 2023
1 parent ba16be6 commit 510a609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Simresults/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public function getName($shorten_lastname=FALSE, $shorten_firstname=FALSE)
$names = explode(' ', $name);
if (count($names) > 1 AND $shorten_lastname) {
$last_name = array_pop($names);

// First character is not a letter, we will not threat this as
// lastname and will try to get another part when more lastname
// parts are available
if (!preg_match('/[a-z]/i', $last_name[0]) and count($names) > 1) {
$last_name = array_pop($names);
}

$name = $names[0]." ".$last_name[0];
}

Expand Down
5 changes: 5 additions & 0 deletions spec/Simresults/DriverSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ function it_can_return_a_shorten_firstname_and_lastname()
$this->setName('Aname with a space at the end ');
$this->getName()->shouldReturn('Aname with a space at the end');
$this->getName(true, true)->shouldReturn('A. e');

// Ignore non letters as lastname
$this->setName('G Mossoni [FNX]');
$this->getName()->shouldReturn('G Mossoni [FNX]');
$this->getName(true, true)->shouldReturn('G. M');
}

}

0 comments on commit 510a609

Please sign in to comment.