class RubyDictionary::CLI

Public Instance Methods

call() click to toggle source
# File lib/ruby_dictionary/cli.rb, line 5
def call
  RubyDictionary::Scraper.scrape_index
  puts "Welcome to the Ruby Dictionary!"
  scrape_slow_classes
  list_klasses
  main_menu
  goodbye
end
goodbye() click to toggle source
# File lib/ruby_dictionary/cli.rb, line 117
def goodbye
  puts "Happy Coding!!!"
end
klass_menu(klass) click to toggle source
# File lib/ruby_dictionary/cli.rb, line 26
def klass_menu(klass)
  input = nil
  puts "\n"
  puts klass.definition
  puts "\nEnter 'i' to see a list of public instance methods\nEnter 'c' to see a list of public class methods\nEnter 'all' to see all public methods available\nEnter the name of a method to learn more\nEnter 'menu' or 'back' to go back to the list of Classes and Mixins\nOr enter 'exit' to quit"
  until input == "menu" || input == "back"
    input = gets.strip.downcase
    case
    when input == "i" || input == "instance"
      klass.list_inst_methods
      puts "\n"
    when input == "more" || input == "next"
      klass.list_inst_methods
    when input == "c" || input == "class"
      klass.list_klass_methods
      puts "\n"
    when input == "all"
      klass.list_all_methods
      puts "\n"
    when input == "menu" || input == "back"
      list_klasses
    when input == "exit"
      puts "Happy Coding!!!"
      exit
    else
      if klass.find_by_name(input) == nil
        puts "Im sorry, I can't find a method by that name, try again or type 'menu' to go to the main menu or type 'exit' to quit"
      else
        method = klass.find_by_name(input)
        puts "\n##{method.name}\n"
        method.callseq.each do |seq|
          puts seq
        end
        puts "\n#{method.description}"
        if method.examples != ""
          puts "\nExamples:\n#{method.examples}\n"
          puts "\nEnter 'i' to see a list of public instance methods\nEnter 'c' to see a list of public class methods\nEnter 'all' to see all public methods available\nEnter the name of a method to learn more\nEnter 'menu' or 'back' to go back to the list of Classes and Mixins\nOr enter 'exit' to quit"
        end
      end
    end
  end
end
list_klasses() click to toggle source
# File lib/ruby_dictionary/cli.rb, line 21
def list_klasses
  RubyDictionary::Klass.all.each.with_index{|k,i| puts "#{i + 1}. #{k.name}"}
  puts "\nEnter the Class or Mixin you would like to explore, or type 'exit' to quit"
end
main_menu() click to toggle source
scrape_slow_classes() click to toggle source
# File lib/ruby_dictionary/cli.rb, line 14
def scrape_slow_classes
  @array = RubyDictionary::Klass.list[0]
  RubyDictionary::Scraper.scrape_klass(@array)
  @enum = RubyDictionary::Klass.list[2]
  RubyDictionary::Scraper.scrape_klass(@enum)
end