diff options
| author | Markus Reiter | 2017-03-11 11:33:12 +0100 |
|---|---|---|
| committer | Markus Reiter | 2017-03-11 21:12:51 +0100 |
| commit | c594ffefbc18933fbd89750a8720e1c0576f4ee7 (patch) | |
| tree | fa2ee42b7fde0552ed7ebde95f600a3cadd6e8c8 /Library/Homebrew/utils | |
| parent | 666ab1438c0aba8d4c0f4b540a5ccdba485f0eca (diff) | |
| download | brew-c594ffefbc18933fbd89750a8720e1c0576f4ee7.tar.bz2 | |
Add `Formatter::pluralize`.
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/formatter.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 8a9afb9af..88616c6f8 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -90,4 +90,20 @@ module Formatter output end + + def pluralize(count, singular, plural = nil) + return "#{count} #{singular}" if count == 1 + + *adjectives, noun = singular.split(" ") + + if plural.nil? + plural = { + "formula" => "formulae", + }.fetch(noun, "#{noun}s") + end + + words = adjectives << plural + + "#{count} #{words.join(" ")}" + end end |
