Merge pull request #2694 from reitermarkus/formatter-pluralize

Use `Formatter::pluralize` where possible.
This commit is contained in:
Markus Reiter 2017-05-29 19:13:12 +02:00 committed by GitHub
commit 0a02d1a029
3 changed files with 9 additions and 10 deletions

View File

@ -55,8 +55,7 @@ module Hbc
end
def self.cask_count_for_tap(tap)
count = tap.cask_files.count
"#{count} #{count == 1 ? "cask" : "casks"}"
Formatter.pluralize(tap.cask_files.count, "cask")
rescue StandardError
"0 #{error_string "error reading #{tap.path}"}"
end

View File

@ -55,7 +55,7 @@ module Homebrew
if rack.directory?
versions = rack.subdirs.map(&:basename)
verb = versions.length == 1 ? "is" : "are"
verb = Formatter.pluralize(versions.length, "is", "are")
puts "#{keg.name} #{versions.join(", ")} #{verb} still installed."
puts "Remove all versions with `brew uninstall --force #{keg.name}`."
end
@ -109,11 +109,11 @@ module Homebrew
protected
def are(items)
items.count == 1 ? "is" : "are"
Formatter.pluralize(items.count, "is", "are", show_count: false)
end
def they(items)
items.count == 1 ? "it" : "they"
Formatter.pluralize(items.count, "it", "they", show_count: false)
end
def list(items)

View File

@ -91,17 +91,17 @@ module Formatter
output
end
def pluralize(count, singular, plural = nil)
return "#{count} #{singular}" if count == 1
def pluralize(count, singular, plural = nil, show_count: true)
return (show_count ? "#{count} #{singular}" : singular.to_s) if count == 1
*adjectives, noun = singular.split(" ")
*adjectives, noun = singular.to_s.split(" ")
plural ||= {
"formula" => "formulae",
}.fetch(noun, "#{noun}s")
words = adjectives << plural
words = adjectives.push(plural).join(" ")
"#{count} #{words.join(" ")}"
show_count ? "#{count} #{words}" : words
end
end