Use Formatter::pluralize where possible.
				
					
				
			This commit is contained in:
		
							parent
							
								
									481a91a92d
								
							
						
					
					
						commit
						d700a5ba18
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user