diff options
| author | Markus Reiter | 2017-03-11 23:35:33 +0100 |
|---|---|---|
| committer | GitHub | 2017-03-11 23:35:33 +0100 |
| commit | 7a8d782365b615e066bead9b4829f6fce7f375df (patch) | |
| tree | 0c6716cdd000e2f45f823450faecf798db957426 /Library/Homebrew/utils | |
| parent | 666ab1438c0aba8d4c0f4b540a5ccdba485f0eca (diff) | |
| parent | 44d367edca03acaa737a3156d05bf462f79f0fc3 (diff) | |
| download | brew-7a8d782365b615e066bead9b4829f6fce7f375df.tar.bz2 | |
Merge pull request #2314 from reitermarkus/formatter-pluralize
Replace `#plural` by `Formatter::pluralize`.
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/formatter.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 8a9afb9af..099b1c6d3 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -90,4 +90,18 @@ module Formatter output end + + def pluralize(count, singular, plural = nil) + return "#{count} #{singular}" if count == 1 + + *adjectives, noun = singular.split(" ") + + plural ||= { + "formula" => "formulae", + }.fetch(noun, "#{noun}s") + + words = adjectives << plural + + "#{count} #{words.join(" ")}" + end end |
