class UI
Attributes
Public Class Methods
browse_control(identifier, page)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 106 def self.browse_control(identifier, page) prompt input = my_gets case input when "n" paginate(identifier) when "m" RubyDoc::CLI.start when "exit!" exit! end if !input.to_i.between?(1,page.count) browse_error(input, identifier, page) else Processor.load_doc(page[input.to_i-1]) end end
browse_error(input, identifier, page)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 394 def self.browse_error(input, identifier, page) if identifier == "Last" list_error(page) browse_control(identifier, page) else browse_list_error(page) browse_control(identifier, page) end end
browse_list(page, identifier)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 247 def self.browse_list(page, identifier) puts sepL page.each_with_index do |doc, index| if doc.type == "Class" || doc.type == "Module" li = ["#{index + 1}.".yellow, doc.name.light_cyan] else li = ["#{index + 1}.".yellow, doc.name.cyan] end puts li.join(" ") end if identifier == "Last" puts sepR puts "End of List".red end puts sepR last_page_menu(page) if identifier == "Last" browse_menu(page) if !(identifier == "Last") browse_control(identifier, page) end
browse_list_error(page)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 404 def self.browse_list_error(page) print redH("\n Enter # to view, 'n' for next page 'm' for main or 'exit!' to leave ") end
clear()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 9 def self.clear system "clear" or system "cls" end
cyanH(str)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 466 def self.cyanH(str) str.colorize(color: :white, background: :cyan) end
display_class(doc, view="short")
click to toggle source
Display===================== ¶ ↑
# File lib/ruby_doc/cli/ui.rb, line 140 def self.display_class(doc, view="short") puts sepL # header # puts "TITLE: ".cyan + doc.name.upcase puts "TYPE: ".cyan + doc.type.upcase puts "\nDESCRIPTION:".cyan # documentation # if view == "short" puts wrapped(doc.short) puts view_full elsif view == "full" puts doc.documentation end # footer # puts "Methods: ".cyan + "#{doc.methods.count}".yellow puts "Source: #{doc.url}".red puts sepR # control # display_class_menu(doc) display_class_control(doc) end
display_class_control(doc)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 54 def self.display_class_control(doc) prompt input = my_gets case input when "full" display_class(doc, "full") when "1" method_list(doc) when "s" Processor.save(doc) when "m" RubyDoc::CLI.start when "exit!" exit! else display_class_error(doc) end end
display_class_error(doc)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 384 def self.display_class_error(doc) print redH("\n Please enter '1' to view methods, 'm' for main, or 'exit!' to leave ") display_class_control(doc) end
display_method(doc)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 166 def self.display_method(doc) puts sepL puts "Title: ".cyan + doc.name.upcase puts "Type: ".cyan + doc.type.upcase puts "\nDescription:".cyan puts doc.documentation puts "Source: #{doc.url}".red puts sepR #-----------future fix------------# # description = doc.doc # puts uie.wrapped(description, 55) #-----------future fix------------# display_method_menu display_method_control(doc) end
display_method_control(doc)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 74 def self.display_method_control(doc) prompt input = my_gets case input when "s" Processor.save(doc) when "m" RubyDoc::CLI.start when "exit!" exit! else display_method_error end end
display_method_error()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 389 def self.display_method_error print redH("\n Please enter 'm' for main menu or 'exit!' to leave ") display_method_control end
favorites_error()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 351 def self.favorites_error sleep(0.1) print redH("\n You have no favorites saved ") main_control end
favorites_list()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 184 def self.favorites_list # Normalize Favorites List list = [] File.open("#{fav_dir}").each do |li| list << li.chomp end # if favorites is empty error & back to main control if list.empty? favorites_error main_control else puts sepL # Iterated and display normalized favorites list list.each_with_index do |f, index| li = ["#{index + 1}.".yellow, f.cyan] puts li.join(" ") end puts sepR list_menu(list) favorites_list_control(list) end end
favorites_list_control(list)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 35 def self.favorites_list_control(list) prompt input = my_gets if input == "reset!" Processor.reset_favs RubyDoc::CLI.start elsif input == "m" RubyDoc::CLI.start elsif input == "exit!" exit! elsif !input.to_i.between?(1,list.count) list_error(list) else Processor.find_fav(list[input.to_i-1]) end favorites_list_control(list) end
learn_more()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 272 def self.learn_more puts sepB puts "FAVORITES".cyan puts sepB puts wrapped("Favorites now persisting to gem directory. Your favorites will be accessible globally throughout all your directories unless/until you uninstall this gem.", 55) puts "\n" puts wrapped("When updating this gem, ruby_doc will check if your favorites file contains any entries (you have favorites saved). If you have entries at the time of the update, it will copy your favorites over to your new (version) gem directory so that you never lose your entries.", 55) puts "\n" puts "Note:".red puts wrapped("The aforementioned 'Update Proof' will not be coded in until the next update but it won't be needed until then regardless so save away.", 55) puts sepB puts "COMING SOON".cyan puts sepB puts "\n" + Scraper.coming_soon + "\n" puts sepB puts "CHANGELOG".cyan puts sepB puts "\n" + Scraper.changelog main_menu("learn") main_control end
list_control(matches)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 90 def self.list_control(matches) prompt input = my_gets if input == "m" RubyDoc::CLI.start elsif input == "exit!" exit! elsif !input.to_i.between?(1,matches.count) list_error(matches) else Processor.load_doc(matches[input.to_i-1]) end list_control(matches) end
list_error(matches)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 372 def self.list_error(matches) if matches.first.is_a?(String) print redH("\n Enter '#' to view, 'reset!', 'm' for main or 'exit!' to leave ") else print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ") end end
loading_animation()
click to toggle source
Goes inside iterator - last line
# File lib/ruby_doc/cli/ui.rb, line 425 def self.loading_animation loading = "" print loading << ". ".cyan if @counter == 50 || @counter == 100 || @counter == 150 || @counter == 200 || @counter == 250 || @counter == 300 || @counter == 350 || @counter == 400 || @counter == 450 || @counter == 500 || @counter == 550 || @counter == 600 || @counter == 650 || @counter == 700 || @counter == 750 || @counter == 800 || @counter == 850 || @counter == 900 || @counter == 950 || @counter == 1000 || @counter == 1150 || @counter == 1200 || @counter == 1250 || @counter == 1300 || @counter == 1350 || @counter == 1400 || @counter == 1450 || @counter == 1500 end
loading_message()
click to toggle source
main_control()
click to toggle source
Control===================== ¶ ↑
# File lib/ruby_doc/cli/ui.rb, line 13 def self.main_control prompt input = my_gets if input.split.size > 1 main_error elsif input == "b" paginate("start") elsif input == "*" favorites_list elsif input == "exit!" exit! elsif input == "?" learn_more else matches = Processor.search(input) search_error if matches.empty? search_list(matches) if matches end end
main_error()
click to toggle source
method_list(doc)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 231 def self.method_list(doc) puts sepR doc.methods.each_with_index do |method, index| if !method.nil? li = ["#{index + 1}.".yellow, method.name.cyan] puts li.join(" ") end end puts sepR list_menu(doc.methods) list_control(doc.methods) end
my_gets()
click to toggle source
nil_error()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 380 def self.nil_error print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ") end
paginate(identifier)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 126 def self.paginate(identifier) case identifier when "start" Processor.page1 when "Page1" Processor.page2 when "Page2" Processor.page3 when "Page3" Processor.last end end
prompt()
click to toggle source
randQ()
click to toggle source
CANDY¶ ↑
Quotes===================== ¶ ↑
# File lib/ruby_doc/cli/ui.rb, line 410 def self.randQ puts sepB html = Nokogiri::HTML(open("https://fortrabbit.github.io/quotes/")) container = html.search(".row.gutter-l.wrap") quotes = container.search("p").map {|quote| quote.text.gsub(/[\n]\s+/, "")} quote = " "+ quotes[rand(0..180)]+ " " wrapped(quote, 55).black end
rdo_prefix()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 470 def self.rdo_prefix "https://ruby-doc.org/core-2.4.3/" end
redH(str)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 462 def self.redH(str) str.colorize(color: :white, background: :red) end
reset_favs_message()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 454 def self.reset_favs_message puts sepB puts "Favorites Deleted!".red puts "Redirecting to main menu ..." puts sepB sleep(2.5) end
search_error()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 357 def self.search_error puts sepB puts "NO CIGAR!".red puts "I couldn't find what you're looking for.".black puts "How about trying a Ruby ".black + "Method" + ", ".black + "Class" + " or ".black + "Module" + " name.".black puts sepB puts "NOT SURE?".red puts "You can always browse with ".black + "'b'" + " & learn something new.".black + ":)" puts sepB print redH("\n Try a new word, enter 'b' to browse, or 'exit!' to leave ") main_control end
search_list(matches)
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 211 def self.search_list(matches) puts sepL matches.each_with_index do |doc, index| if doc.type == "Class" || doc.type == "Module" li = ["#{index + 1}.".yellow, doc.name.light_cyan] else li = ["#{index + 1}.".yellow, doc.name.cyan] end puts li.join(" ") end puts sepR puts "Classes and Modules are".cyan + " Highlighted".light_cyan puts sepR list_menu(matches) list_control(matches) end
sepB()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 450 def self.sepB "=".black*56 end
sepL()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 442 def self.sepL "=".cyan*28 + "=".white*28 end
sepR()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 446 def self.sepR "=".white*28 + "=".cyan*28 end
signature()
click to toggle source
view_full()
click to toggle source
# File lib/ruby_doc/cli/ui.rb, line 474 def self.view_full puts sepB puts "To View Full Documentation Enter".cyan + " full".yellow puts sepB end
wrapped(s, width=60)
click to toggle source
currently not being used
# File lib/ruby_doc/cli/ui.rb, line 481 def self.wrapped(s, width=60) lines = [] line = "" s.split(/\s+/).each do |word| if line.size + word.size >= width lines << line line = word elsif line.empty? line = word else line << " " << word end end lines << line if line return lines.join "\n" end