Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/davidarkemp/Inflector int…
Browse files Browse the repository at this point in the history
…o davidarkemp-master
  • Loading branch information
srkirkland committed Apr 7, 2011
2 parents e7c2d44 + a7818f3 commit 5fd4c81
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
12 changes: 0 additions & 12 deletions Inflector.Tests/Inflector.Tests.csproj
Expand Up @@ -34,19 +34,7 @@
<Reference Include="nunit.framework"> <Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.9.10348\lib\nunit.framework.dll</HintPath> <HintPath>..\packages\NUnit.2.5.9.10348\lib\nunit.framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="nunit.mocks">
<HintPath>..\packages\NUnit.2.5.9.10348\lib\nunit.mocks.dll</HintPath>
</Reference>
<Reference Include="pnunit.framework">
<HintPath>..\packages\NUnit.2.5.9.10348\lib\pnunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CapitalizeTests.cs" /> <Compile Include="CapitalizeTests.cs" />
Expand Down
39 changes: 37 additions & 2 deletions Inflector.Tests/OrdinalizeTests.cs
@@ -1,4 +1,7 @@
using NUnit.Framework; using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;


namespace Inflector.Tests namespace Inflector.Tests
{ {
Expand All @@ -14,6 +17,39 @@ public void Ordinalize()
} }
} }


[TestCase(0, "0th")]
[TestCase(1, "1st")]
[TestCase(2, "2nd")]
[TestCase(3, "3rd")]
[TestCase(4, "4th")]
[TestCase(5, "5th")]
[TestCase(6, "6th")]
[TestCase(7, "7th")]
[TestCase(8, "8th")]
[TestCase(9, "9th")]
[TestCase(10, "10th")]
[TestCase(11, "11th")]
[TestCase(12, "12th")]
[TestCase(13, "13th")]
[TestCase(14, "14th")]
[TestCase(20, "20th")]
[TestCase(21, "21st")]
[TestCase(22, "22nd")]
[TestCase(23, "23rd")]
[TestCase(24, "24th")]
[TestCase(100, "100th")]
[TestCase(101, "101st")]
[TestCase(102, "102nd")]
[TestCase(103, "103rd")]
[TestCase(104, "104th")]
[TestCase(110, "110th")]
[TestCase(1000, "1000th")]
[TestCase(1001, "1001st")]
public void OrdanizeNumbersTest(int number, string ordanized)
{
Assert.AreEqual(number.Ordinalize(), ordanized);
}

public OrdinalizeTests() public OrdinalizeTests()
{ {
TestData.Add("0", "0th"); TestData.Add("0", "0th");
Expand Down Expand Up @@ -44,7 +80,6 @@ public OrdinalizeTests()
TestData.Add("110", "110th"); TestData.Add("110", "110th");
TestData.Add("1000", "1000th"); TestData.Add("1000", "1000th");
TestData.Add("1001", "1001st"); TestData.Add("1001", "1001st");

} }
} }
} }
28 changes: 19 additions & 9 deletions Inflector/Inflector.cs
Expand Up @@ -195,29 +195,39 @@ public static string Uncapitalize(this string word)
return word.Substring(0, 1).ToLower() + word.Substring(1); return word.Substring(0, 1).ToLower() + word.Substring(1);
} }


public static string Ordinalize(this string number) public static string Ordinalize(this string numberString)
{ {
int n = int.Parse(number); return Ordanize(int.Parse(numberString), numberString);
int nMod100 = n % 100; }

public static string Ordinalize(this int number)
{
return Ordanize(number, number.ToString());
}

private static string Ordanize(int number, string numberString)
{
int nMod100 = number % 100;


if (nMod100 >= 11 && nMod100 <= 13) if (nMod100 >= 11 && nMod100 <= 13)
{ {
return number + "th"; return numberString + "th";
} }


switch (n % 10) switch (number % 10)
{ {
case 1: case 1:
return number + "st"; return numberString + "st";
case 2: case 2:
return number + "nd"; return numberString + "nd";
case 3: case 3:
return number + "rd"; return numberString + "rd";
default: default:
return number + "th"; return numberString + "th";
} }
} }



public static string Dasherize(this string underscoredWord) public static string Dasherize(this string underscoredWord)
{ {
return underscoredWord.Replace('_', '-'); return underscoredWord.Replace('_', '-');
Expand Down
8 changes: 2 additions & 6 deletions Inflector/Inflector.csproj
Expand Up @@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Inflector</RootNamespace> <RootNamespace>Inflector</RootNamespace>
<AssemblyName>Inflector</AssemblyName> <AssemblyName>Inflector</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
Expand All @@ -33,11 +34,6 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Inflector.cs" /> <Compile Include="Inflector.cs" />
Expand Down

0 comments on commit 5fd4c81

Please sign in to comment.