From b26e2c39aa46deb9b0b455b3276ab80f479b5e5c Mon Sep 17 00:00:00 2001 From: Justin Edwards Date: Tue, 20 May 2014 22:03:00 -0400 Subject: [PATCH 1/4] update docs to include collection humanization --- readme.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/readme.md b/readme.md index c911b2837..34776b720 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,7 @@ Humanizer meets all your .NET needs for manipulating and displaying strings, enu - [Dehumanize Enums](#dehumanize-enums) - [Humanize DateTime](#humanize-datetime) - [Humanize TimeSpan](#humanize-timespan) + - [Humainze Collections](#humanize-collections) - [Inflector methods](#inflector-methods) - [Pluralize](#pluralize) - [Singularize](#singularize) @@ -308,6 +309,43 @@ TimeSpan.FromMilliseconds(2).Humanize() => "2 milisekundy" TimeSpan.FromMilliseconds(5).Humanize() => "5 milisekúnd" ``` +###Humanize Collections + +You can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default, `ToString()` will be called on each item to get it's representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided("and" in English), but a different separator may be passed into `Humainze`. + +For instance: + +```C# +class SomeClass +{ + public string SomeString; + public int SomeInt; + public override string ToString() + { + return "Specific String"; + } +} + +string FormatSomeClass(SomeClass sc) +{ + return string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString); +} + +var collection = new List + { + new SomeClass { SomeInt = 1, SomeString = "One" }, + new SomeClass { SomeInt = 2, SomeString = "Two" }, + new SomeClass { SomeInt = 3, SomeString = "Three" } + }; + +collection.Humanize() // "Specific String, Specific String, and Specific String" +collection.Humanize("or") //"Specific String, Specific String, or Specific String" +collection.Humanize(FormatSomeClass) //"SomeObject #1 - One, SomeObject #2 - Two, and SomeObject #3 - Three" +collection.Humanize(sc => sc.SomeInt.Ordinalize(), "or") //"1st, 2nd, or 3rd" +``` + +You can provide your own collection formatter by implementing `ICollectionFormatter` and registering it with `Configurator.CollectionFormatters` + ###Inflector methods There are also a few inflector methods: From 6cca9b78c7af09dcf7d0a8067ca91554d5adda34 Mon Sep 17 00:00:00 2001 From: Justin Edwards Date: Tue, 20 May 2014 22:14:36 -0400 Subject: [PATCH 2/4] fix typos in readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 34776b720..eef010ab9 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,7 @@ Humanizer meets all your .NET needs for manipulating and displaying strings, enu - [Dehumanize Enums](#dehumanize-enums) - [Humanize DateTime](#humanize-datetime) - [Humanize TimeSpan](#humanize-timespan) - - [Humainze Collections](#humanize-collections) + - [Humanize Collections](#humanize-collections) - [Inflector methods](#inflector-methods) - [Pluralize](#pluralize) - [Singularize](#singularize) @@ -311,7 +311,7 @@ TimeSpan.FromMilliseconds(5).Humanize() => "5 milisekúnd" ###Humanize Collections -You can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default, `ToString()` will be called on each item to get it's representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided("and" in English), but a different separator may be passed into `Humainze`. +You can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default `ToString()` will be called on each item to get its representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided("and" in English), but a different separator may be passed into `Humainze`. For instance: From e9caca981782739187734b6f64234cf3f6b1e764 Mon Sep 17 00:00:00 2001 From: Justin Edwards Date: Tue, 20 May 2014 22:17:56 -0400 Subject: [PATCH 3/4] allign example output --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index eef010ab9..6b8ccde30 100644 --- a/readme.md +++ b/readme.md @@ -338,9 +338,9 @@ var collection = new List new SomeClass { SomeInt = 3, SomeString = "Three" } }; -collection.Humanize() // "Specific String, Specific String, and Specific String" -collection.Humanize("or") //"Specific String, Specific String, or Specific String" -collection.Humanize(FormatSomeClass) //"SomeObject #1 - One, SomeObject #2 - Two, and SomeObject #3 - Three" +collection.Humanize() // "Specific String, Specific String, and Specific String" +collection.Humanize("or") //"Specific String, Specific String, or Specific String" +collection.Humanize(FormatSomeClass) //"SomeObject #1 - One, SomeObject #2 - Two, and SomeObject #3 - Three" collection.Humanize(sc => sc.SomeInt.Ordinalize(), "or") //"1st, 2nd, or 3rd" ``` From ce639036279c625d1499e01e495d7fc0c9dd6640 Mon Sep 17 00:00:00 2001 From: Justin Edwards Date: Tue, 20 May 2014 22:27:53 -0400 Subject: [PATCH 4/4] you'd think by now I'd be able to get the name right... --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6b8ccde30..afc6832a8 100644 --- a/readme.md +++ b/readme.md @@ -311,7 +311,7 @@ TimeSpan.FromMilliseconds(5).Humanize() => "5 milisekúnd" ###Humanize Collections -You can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default `ToString()` will be called on each item to get its representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided("and" in English), but a different separator may be passed into `Humainze`. +You can call `Humanize` on any `IEnumerable` to get a nicely formatted string representing the objects in the collection. By default `ToString()` will be called on each item to get its representation but a formatting function may be passed to `Humanize` instead. Additionally, a default separator is provided("and" in English), but a different separator may be passed into `Humanize`. For instance: