From d700a5ba188b0a01fba21401c4432239c29835bc Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 29 May 2017 17:50:13 +0200 Subject: [PATCH] Use `Formatter::pluralize` where possible. --- Library/Homebrew/cask/lib/hbc/cli/doctor.rb | 3 +-- Library/Homebrew/cmd/uninstall.rb | 6 +++--- Library/Homebrew/utils/formatter.rb | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 64cd11f9e2..fe7889b731 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -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 diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 9c51a0d1cc..4839ba1e06 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -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) diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 099b1c6d35..a29b43c8de 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -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