diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal.php b/src/Coduo/PHPHumanizer/Number/Ordinal.php index c507951..4868b09 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal.php @@ -27,10 +27,15 @@ public function __construct($number, $locale) $this->strategy = Builder::build($locale); } + public function isPrefix() + { + return $this->strategy->isPrefix(); + } + public function __toString() { return $this ->strategy - ->ordinalSuffix($this->number); + ->ordinalIndicator($this->number); } -} +} \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php index 4ae2c53..470e87a 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php @@ -4,10 +4,15 @@ interface StrategyInterface { + /** + * @return boolean + */ + public function isPrefix(); + /** * @param int|float $number * * @return string */ - public function ordinalSuffix($number); + public function ordinalIndicator($number); } diff --git a/src/Coduo/PHPHumanizer/NumberHumanizer.php b/src/Coduo/PHPHumanizer/NumberHumanizer.php index ab92ecd..b2354a9 100644 --- a/src/Coduo/PHPHumanizer/NumberHumanizer.php +++ b/src/Coduo/PHPHumanizer/NumberHumanizer.php @@ -17,9 +17,13 @@ final class NumberHumanizer */ public static function ordinalize($number, $locale = 'en') { - return $number.self::ordinal($number, $locale); + $ordinal = new Ordinal($number, $locale); + if ($ordinal->isPrefix()) { + return (string) $ordinal.$number; + } + else return (string) $number.$ordinal; } - + /** * @param int|float $number * @param string $locale @@ -29,7 +33,6 @@ public static function ordinalize($number, $locale = 'en') public static function ordinal($number, $locale = 'en') { $ordinal = new Ordinal($number, $locale); - return (string) $ordinal; } diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php index 7cda141..5b7ebb7 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php @@ -6,8 +6,13 @@ final class EnStrategy implements StrategyInterface { + /** {@inheritdoc}*/ + public function isPrefix(){ + return False; + } + /** {@inheritdoc} */ - public function ordinalSuffix($number) + public function ordinalIndicator($number) { $absNumber = abs((integer) $number); diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php new file mode 100644 index 0000000..e4ba1e4 --- /dev/null +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php @@ -0,0 +1,19 @@ +assertEquals($expected, NumberHumanizer::ordinal($number, 'nl')); } + /** + * @dataProvider ordinalIndicatorIndonesianProvider + * @param $expected + * @param $number + */ + public function test_return_ordinal_suffix_indonesian($expected, $number) + { + $this->assertEquals($expected, NumberHumanizer::ordinal($number, 'id')); + } + /** * @dataProvider ordinalizeDataProvider * @depends test_return_ordinal_suffix @@ -51,6 +61,18 @@ public function test_ordinalize_numbers_dutch($expected, $number) $this->assertEquals($expected, NumberHumanizer::ordinalize($number, 'nl')); } + /** + * @dataProvider ordinalizeDataIndonesianProvider + * @depends test_return_ordinal_suffix_indonesian + * + * @param $expected + * @param $number + */ + public function test_ordinalize_numbers_indonesian($expected, $number) + { + $this->assertEquals($expected, NumberHumanizer::ordinalize($number, 'id')); + } + /** * @dataProvider binarySuffixDataProvider * @@ -164,6 +186,48 @@ public function test_statically_throw_exception_when_converting_roman_number_is_ NumberHumanizer::fromRoman($number); } + /** + * @return array + */ + public function ordinalIndicatorProvider() + { + return array( + array('st', 1), + array('nd', 2), + array('rd', 23), + array('nd', 1002), + array('th', -111), + ); + } + + /** + * @return array + */ + public function ordinalIndicatorDutchProvider() + { + return array( + array('e', 1), + array('e', 2), + array('e', 23), + array('e', 1002), + array('e', -111), + ); + } + + /** + * @return array + */ + public function ordinalIndicatorIndonesianProvider() + { + return array( + array('ke-', 1), + array('ke-', 2), + array('ke-', 23), + array('ke-', 1002), + array('ke-', -111), + ); + } + /** * @return array */ @@ -195,28 +259,14 @@ public function ordinalizeDataDutchProvider() /** * @return array */ - public function ordinalSuffixProvider() + public function ordinalizeDataIndonesianProvider() { return array( - array('st', 1), - array('nd', 2), - array('rd', 23), - array('nd', 1002), - array('th', -111), - ); - } - - /** - * @return array - */ - public function ordinalSuffixDutchProvider() - { - return array( - array('e', 1), - array('e', 2), - array('e', 23), - array('e', 1002), - array('e', -111), + array('ke-1', 1), + array('ke-2', 2), + array('ke-23', 23), + array('ke-1002', 1002), + array('ke--111', -111), ); }