Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RussianOrdinalizer #221

Merged
merged 2 commits into from
Apr 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
###In Development
- [#217](https://github.com/Mehdik/Humanizer/pull/217): Changed OrdinalizeExtensions to better accommodate localisations. Added pt-BR and Spanish Ordinalize localisation.
- [#221](https://github.com/Mehdik/Humanizer/pull/221): Added Russian ordinalizer

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.22.1...master)

Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Localisation\pt-BR\NumberToWordsTests.cs" />
<Compile Include="Localisation\pt-BR\OrdinalizeTests.cs" />
<Compile Include="Localisation\ru-RU\NumberToWordsTests.cs" />
<Compile Include="Localisation\ru-RU\OrdinalizeTests.cs" />
<Compile Include="Localisation\ru-RU\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\sk\DateHumanizeTests.cs" />
<Compile Include="Localisation\ar\DateHumanizeTests.cs" />
Expand Down
129 changes: 129 additions & 0 deletions src/Humanizer.Tests/Localisation/ru-RU/OrdinalizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Xunit;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.ruRU
{
public class OrdinalizeTests : AmbientCulture
{
public OrdinalizeTests()
: base("ru-RU")
{
}

[Theory]
[InlineData("0", "0-й")]
[InlineData("1", "1-й")]
[InlineData("2", "2-й")]
[InlineData("3", "3-й")]
[InlineData("4", "4-й")]
[InlineData("5", "5-й")]
[InlineData("6", "6-й")]
[InlineData("23", "23-й")]
[InlineData("100", "100-й")]
[InlineData("101", "101-й")]
[InlineData("102", "102-й")]
[InlineData("103", "103-й")]
[InlineData("1001", "1001-й")]
public void OrdinalizeString(string number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized);
}

[Theory]
[InlineData("0", "0-я")]
[InlineData("1", "1-я")]
[InlineData("2", "2-я")]
[InlineData("3", "3-я")]
[InlineData("4", "4-я")]
[InlineData("5", "5-я")]
[InlineData("6", "6-я")]
[InlineData("23", "23-я")]
[InlineData("100", "100-я")]
[InlineData("101", "101-я")]
[InlineData("102", "102-я")]
[InlineData("103", "103-я")]
[InlineData("1001", "1001-я")]
public void OrdinalizeStringFeminine(string number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized);
}

[Theory]
[InlineData("0", "0-е")]
[InlineData("1", "1-е")]
[InlineData("2", "2-е")]
[InlineData("3", "3-е")]
[InlineData("4", "4-е")]
[InlineData("5", "5-е")]
[InlineData("6", "6-е")]
[InlineData("23", "23-е")]
[InlineData("100", "100-е")]
[InlineData("101", "101-е")]
[InlineData("102", "102-е")]
[InlineData("103", "103-е")]
[InlineData("1001", "1001-е")]
public void OrdinalizeStringNeuter(string number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Neuter), ordinalized);
}

[Theory]
[InlineData(0, "0-й")]
[InlineData(1, "1-й")]
[InlineData(2, "2-й")]
[InlineData(3, "3-й")]
[InlineData(4, "4-й")]
[InlineData(5, "5-й")]
[InlineData(6, "6-й")]
[InlineData(10, "10-й")]
[InlineData(23, "23-й")]
[InlineData(100, "100-й")]
[InlineData(101, "101-й")]
[InlineData(102, "102-й")]
[InlineData(103, "103-й")]
[InlineData(1001, "1001-й")]
public void OrdinalizeNumber(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Masculine), ordinalized);
}

[Theory]
[InlineData(0, "0-я")]
[InlineData(1, "1-я")]
[InlineData(2, "2-я")]
[InlineData(3, "3-я")]
[InlineData(4, "4-я")]
[InlineData(5, "5-я")]
[InlineData(6, "6-я")]
[InlineData(10, "10-я")]
[InlineData(23, "23-я")]
[InlineData(100, "100-я")]
[InlineData(101, "101-я")]
[InlineData(102, "102-я")]
[InlineData(103, "103-я")]
[InlineData(1001, "1001-я")]
public void OrdinalizeNumberFeminine(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Feminine), ordinalized);
}

[Theory]
[InlineData(0, "0-е")]
[InlineData(1, "1-е")]
[InlineData(2, "2-е")]
[InlineData(3, "3-е")]
[InlineData(4, "4-е")]
[InlineData(5, "5-е")]
[InlineData(6, "6-е")]
[InlineData(23, "23-е")]
[InlineData(100, "100-е")]
[InlineData(101, "101-е")]
[InlineData(102, "102-е")]
[InlineData(103, "103-е")]
[InlineData(1001, "1001-е")]
public void OrdinalizeNumberNeuter(int number, string ordinalized)
{
Assert.Equal(number.Ordinalize(GrammaticalGender.Neuter), ordinalized);
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Localisation\NumberToWords\PolishNumberToWordsConverter.cs" />
<Compile Include="Localisation\NumberToWords\RussianNumberToWordsConverter.cs" />
<Compile Include="Localisation\Formatters\HebrewFormatter.cs" />
<Compile Include="Localisation\Ordinalizers\RussianOrdinalizer.cs" />
<Compile Include="Localisation\Ordinalizers\SpanishOrdinalizer.cs" />
<Compile Include="Localisation\Ordinalizers\DefaultOrdinalizer.cs" />
<Compile Include="Localisation\Ordinalizers\EnglishOrdinalizer.cs" />
Expand Down
21 changes: 21 additions & 0 deletions src/Humanizer/Localisation/Ordinalizers/RussianOrdinalizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Humanizer.Localisation.Ordinalizers
{
internal class RussianOrdinalizer : DefaultOrdinalizer
{
public override string Convert(int number, string numberString)
{
return Convert(number, numberString, GrammaticalGender.Masculine);
}

public override string Convert(int number, string numberString, GrammaticalGender gender)
{
if (gender == GrammaticalGender.Masculine)
return numberString + "-й";

if (gender == GrammaticalGender.Feminine)
return numberString + "-я";

return numberString + "-е";
}
}
}
3 changes: 2 additions & 1 deletion src/Humanizer/OrdinalizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public static class OrdinalizeExtensions
{
{"en", () => new EnglishOrdinalizer()},
{"es", () => new SpanishOrdinalizer()},
{"pt-BR", () => new BrazilianPortugueseOrdinalizer()}
{"pt-BR", () => new BrazilianPortugueseOrdinalizer()},
{"ru", () => new RussianOrdinalizer()}
};

/// <summary>
Expand Down