class Cookbooks::Highest
Constants
- DISPLAY_N_PROGRAMS_BY_DEFAULT
#¶ ↑
DISPLAY_N_PROGRAMS_BY_DEFAULT¶ ↑
How many programs to display by default.
#¶ ↑
- EXIT_ON_MISSING_ENTRY
#¶ ↑
EXIT_ON_MISSING_ENTRY¶ ↑
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE¶ ↑
#¶ ↑
Public Class Methods
new( display_n = DISPLAY_N_PROGRAMS_BY_DEFAULT, run_already = true )
click to toggle source
#¶ ↑
initialize¶ ↑
To use more than the defaults, you can do this:
Cookbooks::Highest.new(150)
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 48 def initialize( display_n = DISPLAY_N_PROGRAMS_BY_DEFAULT, run_already = true ) reset startup set_display_top_n(display_n) # First set how many programs we will display. run if run_already end
Public Instance Methods
available_programs?()
click to toggle source
beautify_file_size(i)
click to toggle source
#¶ ↑
#beautify_file_size¶ ↑
This will attempt to beautify the given input.
We require 3 trailing positions after the , position.
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 167 def beautify_file_size(i) i = i.to_s.strip x = i.to_f kb = 1024 mb = (1024 ** 2) gb = (1024 ** 3) # tb = (1024 ** 4) if x < 1024 return "#{round(x.to_f)} bytes" elsif x > 1024 && x < mb return "#{round(x.to_f/kb)} kb" elsif x > mb && x < gb result = round(x.to_f/mb) result = '%.3f' % result return "#{result} MB" elsif x > gb return "#{round(x.to_f/gb)} GB" end end
display_n?()
click to toggle source
inform_the_user_what_we_will_do()
click to toggle source
#¶ ↑
#inform_the_user_what_we_will_do¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 83 def inform_the_user_what_we_will_do # Get the local URL. opnn; e 'Now fetching the top `'+simp(@display_top_n.to_s)+ '` largest local programs from the directory' opnn; e ' `'+sdir(source_directory?)+'`.' opnn; e 'This may take a while. Please be patient.' end
notify_the_user_that_we_have_finished_fetching_the_local_urls()
click to toggle source
#¶ ↑
#notify_the_user_that_we_have_finished_fetching_the_local_urls¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 94 def notify_the_user_that_we_have_finished_fetching_the_local_urls opnn; e # Add a newline. opnn; e 'Finished fetching the local URLs. We will display them now.'+N opnn; e end
opnn()
click to toggle source
report_results()
click to toggle source
#¶ ↑
#report_results¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 204 def report_results sort_results n_rjust = display_n?.to_s.size @results.each_with_index { |entry, index| index += 1 index = index.to_s.rjust(n_rjust) # For now, we shorten the url. local_url = remove_file_suffix( File.basename(entry.first).strip ).strip local_url = '%-36s' % local_url # Then we pad it. _ = '%.3f' % entry[1].to_s filesize = '%12s' % beautify_file_size(_) opnn; e ' ('+sfancy(index)+') '+local_url+' '+swarn(filesize) } end
reset()
click to toggle source
round(number, n_positions = 3)
click to toggle source
run()
click to toggle source
sanitize_available_programs()
click to toggle source
#¶ ↑
#sanitize_available_programs¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 229 def sanitize_available_programs array = [] # Dump the information into this array here. _ = @available_programs _.each {|i| # ===================================================================== # # Obtain the dataset for this program next. # ===================================================================== # @dataset = Cookbooks::Cookbook.new(i) { :be_quiet_and_bypass_menu } url = @dataset.local_url? # Keep the local URL here. if url.nil? e '`'+simp(i.to_s)+'` is nil, probably because it does not '\ 'exist locally.' e 'Please consider fixing this problem.' if EXIT_ON_MISSING_ENTRY e 'We will exit now as the constant EXIT_ON_MISSING_ENTRY '\ 'was set to true.' exit end end size = @dataset.size? # Keep the filesize here. if url array << [ url, size ] # Then append into the main Array containing this information. end } @available_programs = array # Store it here finally. end
set_display_top_n( i = DISPLAY_N_PROGRAMS_BY_DEFAULT )
click to toggle source
#¶ ↑
#set_display_top_n¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 112 def set_display_top_n( i = DISPLAY_N_PROGRAMS_BY_DEFAULT ) if i.is_a? Array # Handle arrays first. if i.empty? i = DISPLAY_N_PROGRAMS_BY_DEFAULT # Use default. else i = i.first end elsif i.is_a? Symbol case i # case tag when :display_ten_programs i = 10 when :display_twenty_programs i = 20 end end case i # case tag # ======================================================================= # # === highest --help # ======================================================================= # when /-?-?help/,'HELP' show_help; exit end i = i.to_i unless i.is_a? Integer # ======================================================================= # # Ensure that we will not grab too many entries. # ======================================================================= # i = available_programs?.size.to_i if i > available_programs?.size.to_i @display_top_n = i end
show_help()
click to toggle source
#¶ ↑
#show_help (help tag)¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/highest.rb, line 147 def show_help if Object.const_defined? :ClassDocuShower ClassDocuShower[__FILE__] end e 'This class does not have many special commands.' e e 'You can pass in a number, which simply means how many' e 'programs will be displayed, e. g. as in:' e e ' highest 250' e end
sort_results()
click to toggle source