class Rudisco::CLI::Presentation::Find

Attributes

records[R]

@return Array<Rudisco::Gem>

Public Class Methods

new(**params) click to toggle source
# File lib/rudisco/cli/presentation/find.rb, line 6
def initialize(**params) # no-doc
  @records = params[:records]
end

Public Instance Methods

show() click to toggle source
# File lib/rudisco/cli/presentation/find.rb, line 10
def show # no-doc
  report message: '', complete: '' do
    if records.count.zero?
      nothing_was_found
    else
      show_results
    end
  end # report
end

Private Instance Methods

clear_desc_helper(description) click to toggle source

Returns copy of description string, but without special symbols.

@param [String] description

Original string.

@return [String]

# File lib/rudisco/cli/presentation/find.rb, line 69
def clear_desc_helper(description)
  return "N/A" if description.nil? || description.empty?

  tmp = description.dup
  tmp = tmp.delete "#{1.chr}-#{31.chr}".split.join ' '

  return tmp
end
nothing_was_found() click to toggle source
# File lib/rudisco/cli/presentation/find.rb, line 26
def nothing_was_found # no-doc
  header title: 'Rudisco search results',
         width: 80, align: 'center',
         bold: true, timestamp: true

  aligned "Nothing was found. Sorry.", bold: true, width: 80,
                                       align: 'center'
end
show_results() click to toggle source
# File lib/rudisco/cli/presentation/find.rb, line 35
def show_results # no-doc
  header title: 'Rudisco search results',
         width: 80, align: 'center',
         bold: true, timestamp: true

  table(border: true) do
    row do
      column '№',            width: 3,  align: 'center'
      column 'Name',         width: 17, align: 'center'
      column 'Git',          width: 3,  align: 'center'
      column 'Description',  width: 46, align: 'center'
      column 'DW (total)',   width: 10, align: 'center'
    end
    records.each_with_index do |rec, index|
      row do
        column index
        column rec.name
        column source_code_helper(rec.source_code_url)
        column clear_desc_helper(rec.description)
        column rec.total_downloads
      end
    end
  end # table
end
source_code_helper(source_code_url) click to toggle source
# File lib/rudisco/cli/presentation/find.rb, line 78
def source_code_helper(source_code_url) # no-doc
  if source_code_url.nil? || source_code_url.empty?
    return "-"
  else
    return "+"
  end
end