< Summary

Information
Class: MyNet.Humanizer.QuantifyExtensions
Assembly: MyNet.Humanizer
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Extensions/QuantifyExtensions.cs
Tag: 323_28699572109
Line coverage
66%
Covered lines: 4
Uncovered lines: 2
Coverable lines: 6
Total lines: 95
Line coverage: 66.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Quantify(...)100%11100%
Quantify(...)100%11100%
Quantify(...)100%11100%
Quantify(...)100%11100%
Quantify(...)100%210%
Quantify(...)100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Humanizer/Extensions/QuantifyExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="QuantifyExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Globalization;
 8using MyNet.Primitives;
 9using MyNet.Text.Templating;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Humanizer;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15/// <summary>
 16/// Provides extensions for formatting a <see cref="string"/> word as a quantity.
 17/// </summary>
 18public static class QuantifyExtensions
 19{
 20    extension(string input)
 21    {
 22        /// <summary>
 23        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 24        /// </summary>
 25        /// <param name="quantity">The quantity of the word.</param>
 26        /// <param name="format">A standard or custom numeric format string.</param>
 27        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 28        /// <example>
 29        /// "request".Quantify(0) => "0 requests"
 30        /// "request".Quantify(10000, format: "N0") => "10,000 requests"
 31        /// "request".Quantify(1, format: "N0") => "1 request".
 32        /// </example>
 1533        public string Quantify(int quantity, string? format = null, CultureInfo? culture = null) => input.Quantify((deci
 34
 35        /// <summary>
 36        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 37        /// </summary>
 38        /// <param name="quantity">The quantity of the word.</param>
 39        /// <param name="format">A standard or custom numeric format string.</param>
 40        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 41        /// <example>
 42        /// "request".Quantify(0) => "0 requests"
 43        /// "request".Quantify(10000, format: "N0") => "10,000 requests"
 44        /// "request".Quantify(1, format: "N0") => "1 request".
 45        /// </example>
 2146        public string Quantify(double quantity, string? format = null, CultureInfo? culture = null) => input.Quantify((d
 47
 48        /// <summary>
 49        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 50        /// </summary>
 51        /// <param name="quantity">The quantity of the word.</param>
 52        /// <param name="format">A standard or custom numeric format string.</param>
 53        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 54        /// <returns>The formatted quantity string.</returns>
 55        public string Quantify(decimal quantity, string? format = null, CultureInfo? culture = null)
 3656            => TextTemplating.Create(x => x.PrefixWithQuantity(quantity, format)).Apply(input, culture.OrCurrent());
 57    }
 58
 59    extension(int quantity)
 60    {
 61        /// <summary>
 62        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 63        /// </summary>
 64        /// <param name="word">The word to be formatted.</param>
 65        /// <param name="format">A standard or custom numeric format string.</param>
 66        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 67        /// <returns>The formatted quantity string.</returns>
 368        public string Quantify(string word, string? format = null, CultureInfo? culture = null) => word.Quantify(quantit
 69    }
 70
 71    extension(double quantity)
 72    {
 73        /// <summary>
 74        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 75        /// </summary>
 76        /// <param name="word">The word to be formatted.</param>
 77        /// <param name="format">A standard or custom numeric format string.</param>
 78        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 79        /// <returns>The formatted quantity string.</returns>
 080        public string Quantify(string word, string? format = null, CultureInfo? culture = null) => word.Quantify(quantit
 81    }
 82
 83    extension(decimal quantity)
 84    {
 85        /// <summary>
 86        /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word.
 87        /// </summary>
 88        /// <param name="word">The word to be formatted.</param>
 89        /// <param name="format">A standard or custom numeric format string.</param>
 90        /// <param name="culture">An object that supplies culture-specific formatting information.</param>
 91        /// <returns>The formatted quantity string.</returns>
 092        public string Quantify(string word, string? format = null, CultureInfo? culture = null) => word.Quantify(quantit
 93    }
 94}
 95