Use Formatter::pluralize where possible.
This commit is contained in:
parent
481a91a92d
commit
d700a5ba18
@ -55,8 +55,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.cask_count_for_tap(tap)
|
def self.cask_count_for_tap(tap)
|
||||||
count = tap.cask_files.count
|
Formatter.pluralize(tap.cask_files.count, "cask")
|
||||||
"#{count} #{count == 1 ? "cask" : "casks"}"
|
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
"0 #{error_string "error reading #{tap.path}"}"
|
"0 #{error_string "error reading #{tap.path}"}"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -55,7 +55,7 @@ module Homebrew
|
|||||||
|
|
||||||
if rack.directory?
|
if rack.directory?
|
||||||
versions = rack.subdirs.map(&:basename)
|
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 "#{keg.name} #{versions.join(", ")} #{verb} still installed."
|
||||||
puts "Remove all versions with `brew uninstall --force #{keg.name}`."
|
puts "Remove all versions with `brew uninstall --force #{keg.name}`."
|
||||||
end
|
end
|
||||||
@ -109,11 +109,11 @@ module Homebrew
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def are(items)
|
def are(items)
|
||||||
items.count == 1 ? "is" : "are"
|
Formatter.pluralize(items.count, "is", "are", show_count: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def they(items)
|
def they(items)
|
||||||
items.count == 1 ? "it" : "they"
|
Formatter.pluralize(items.count, "it", "they", show_count: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list(items)
|
def list(items)
|
||||||
|
|||||||
@ -91,17 +91,17 @@ module Formatter
|
|||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def pluralize(count, singular, plural = nil)
|
def pluralize(count, singular, plural = nil, show_count: true)
|
||||||
return "#{count} #{singular}" if count == 1
|
return (show_count ? "#{count} #{singular}" : singular.to_s) if count == 1
|
||||||
|
|
||||||
*adjectives, noun = singular.split(" ")
|
*adjectives, noun = singular.to_s.split(" ")
|
||||||
|
|
||||||
plural ||= {
|
plural ||= {
|
||||||
"formula" => "formulae",
|
"formula" => "formulae",
|
||||||
}.fetch(noun, "#{noun}s")
|
}.fetch(noun, "#{noun}s")
|
||||||
|
|
||||||
words = adjectives << plural
|
words = adjectives.push(plural).join(" ")
|
||||||
|
|
||||||
"#{count} #{words.join(" ")}"
|
show_count ? "#{count} #{words}" : words
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user