Dropped Number class
Actually just moved it to joshtronic/php-ordinalindicator
This commit is contained in:
parent
9d5dac05c3
commit
68b2f83379
2 changed files with 0 additions and 118 deletions
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Number Utility Collection
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2007-2014, Josh Sherman
|
||||
* @license http://www.opensource.org/licenses/mit-license.html
|
||||
* @link https://github.com/joshtronic/pickles
|
||||
* @package Pickles
|
||||
*/
|
||||
|
||||
namespace Pickles;
|
||||
|
||||
/**
|
||||
* Number Class
|
||||
*
|
||||
* Just a simple collection of static functions to accomplish some of the more
|
||||
* redundant numeric related manipulation.
|
||||
*/
|
||||
class Number
|
||||
{
|
||||
/**
|
||||
* Ordinal Indiciator
|
||||
*
|
||||
* Formats a number by appending an ordinal indicator.
|
||||
*
|
||||
* @static
|
||||
* @link http://en.wikipedia.org/wiki/Ordinal_indicator
|
||||
* @link http://en.wikipedia.org/wiki/English_numerals#Ordinal_numbers
|
||||
* @param string $number number to format
|
||||
* @param boolean $superscript include <sup> tags
|
||||
* @return string formatted number
|
||||
*/
|
||||
public static function ordinalIndicator($number, $superscript = false)
|
||||
{
|
||||
if (!in_array(($number % 100), [11, 12, 13]))
|
||||
{
|
||||
switch ($number % 10)
|
||||
{
|
||||
case 1:
|
||||
$suffix = 'st';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$suffix = 'nd';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$suffix = 'rd';
|
||||
break;
|
||||
|
||||
default:
|
||||
$suffix = 'th';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($superscript)
|
||||
{
|
||||
$suffix = '<sup>' . $suffix . '</sup>';
|
||||
}
|
||||
|
||||
return $number . $suffix;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
class NumberTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorNoSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorNoSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Pickles\Number::ordinalIndicator($a));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorNoSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1st'],
|
||||
[2, '2nd'],
|
||||
[3, '3rd'],
|
||||
[4, '4th'],
|
||||
[51, '51st'],
|
||||
[52, '52nd'],
|
||||
[53, '53rd'],
|
||||
[54, '54th'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerOrginalIndicatorSuper
|
||||
*/
|
||||
public function testOrdinalIndicatorSuper($a, $b)
|
||||
{
|
||||
$this->assertEquals($b, Pickles\Number::ordinalIndicator($a, true));
|
||||
}
|
||||
|
||||
public function providerOrginalIndicatorSuper()
|
||||
{
|
||||
return [
|
||||
[1, '1<sup>st</sup>'],
|
||||
[2, '2<sup>nd</sup>'],
|
||||
[3, '3<sup>rd</sup>'],
|
||||
[4, '4<sup>th</sup>'],
|
||||
[51, '51<sup>st</sup>'],
|
||||
[52, '52<sup>nd</sup>'],
|
||||
[53, '53<sup>rd</sup>'],
|
||||
[54, '54<sup>th</sup>'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue