Last active
January 4, 2016 05:49
-
-
Save vaneves/8577810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CharacterParser | |
{ | |
private $charaters = array( | |
'a' => 'ka', | |
'b' => 'tu', | |
'c' => 'mi', | |
'd' => 'te', | |
'e' => 'ku', | |
'f' => 'lu', | |
'g' => 'ji', | |
'h' => 'ri', | |
'i' => 'ki', | |
'j' => 'zu', | |
'k' => 'me', | |
'l' => 'ta', | |
'm' => 'rin', | |
'n' => 'to', | |
'o' => 'mo', | |
'p' => 'no', | |
'q' => 'ke', | |
'r' => 'shi', | |
's' => 'ari', | |
't' => 'chi', | |
'u' => 'do', | |
'v' => 'ru', | |
'x' => 'na', | |
'w' => 'mei', | |
'y' => 'fu', | |
'z' => 'ra' | |
); | |
public function parse($char) | |
{ | |
if(isset($this->charaters[$char])) | |
return $this->charaters[$char]; | |
return ' '; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class NameParser | |
{ | |
private $originalName; | |
private $parsedName; | |
public function __construct($name) | |
{ | |
$this->originalName = strtolower($name); | |
} | |
public function parse() | |
{ | |
$name = ''; | |
$char = new CharacterParser(); | |
$count = strlen($this->originalName); | |
for($i = 0; $i < $count; $i++) | |
$name .= $char->parse($this->originalName[$i]); | |
$this->parsedName = preg_replace('/\s{2,}/', ' ', trim($name)); | |
} | |
public function getName() | |
{ | |
return $this->parsedName; | |
} | |
public function __toString() | |
{ | |
return $this->parsedName; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once './CharacterParser.php'; | |
require_once './NameParser.php'; | |
if(count($argv) != 2) | |
{ | |
echo 'Quantidade de parâmetros inválida.' . PHP_EOL; | |
echo 'Ex.: php soluction.php nome' . PHP_EOL; | |
echo 'Ex.: php soluction.php "nome sobrenome"' . PHP_EOL; | |
exit(); | |
} | |
$parser = new NameParser($argv[1]); | |
$parser->parse(); | |
echo $parser->getName() . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment