Class: Descriptions Private
- Inherits:
-
Object
- Object
- Descriptions
- Extended by:
- Homebrew::Search
- Defined in:
- Library/Homebrew/descriptions.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Helper class for printing and searching descriptions.
Class Method Summary collapse
-
.search(string_or_regex, field, cache_store) ⇒ Object
private
Given a regex, find all formulae whose specified fields contain a match.
Instance Method Summary collapse
-
#initialize(descriptions) ⇒ Descriptions
constructor
private
Create an actual instance.
-
#print ⇒ Object
private
Take search results -- a hash mapping formula names to descriptions -- and print them.
Methods included from Homebrew::Search
query_regexp, search_casks, search_descriptions, search_formulae, search_taps
Constructor Details
#initialize(descriptions) ⇒ Descriptions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create an actual instance.
32 33 34 |
# File 'Library/Homebrew/descriptions.rb', line 32 def initialize(descriptions) @descriptions = descriptions end |
Class Method Details
.search(string_or_regex, field, cache_store) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Given a regex, find all formulae whose specified fields contain a match.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'Library/Homebrew/descriptions.rb', line 16 def self.search(string_or_regex, field, cache_store) cache_store.populate_if_empty! results = case field when :name cache_store.search(string_or_regex) { |name, _| name } when :desc cache_store.search(string_or_regex) { |_, desc| desc } when :either cache_store.search(string_or_regex) end new(results) end |
Instance Method Details
#print ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Take search results -- a hash mapping formula names to descriptions -- and print them.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'Library/Homebrew/descriptions.rb', line 38 def print blank = Formatter.warning("[no description]") @descriptions.keys.sort.each do |full_name| short_name = short_names[full_name] printed_name = if short_name_counts[short_name] == 1 short_name else full_name end description = @descriptions[full_name] || blank puts "#{Tty.bold}#{printed_name}:#{Tty.reset} #{description}" end end |