Class: RubyDictionary::CLI
- Inherits:
-
Object
- Object
- RubyDictionary::CLI
- Defined in:
- lib/ruby_dictionary/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #klass_menu(klass) ⇒ Object
- #list_klasses ⇒ Object
- #main_menu ⇒ Object
- #scrape_slow_classes ⇒ Object
Instance Method Details
#call ⇒ Object
5 6 7 8 9 10 11 12 |
# 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 goodbye end |
#goodbye ⇒ Object
117 118 119 |
# File 'lib/ruby_dictionary/cli.rb', line 117 def goodbye puts "Happy Coding!!!" end |
#klass_menu(klass) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_dictionary/cli.rb', line 26 def (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 ⇒ Object
21 22 23 24 |
# 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 ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ruby_dictionary/cli.rb', line 69 def input = nil until input == "exit" input = gets.strip.downcase case input when "list" list_klasses when /array(s)?\b|1/ (@array) when /dir(s)?\b|2/ @dir = RubyDictionary::Klass.list[1] RubyDictionary::Scraper.scrape_klass(@dir) (@dir) when /enumerable(s)?\b|3/ (@enum) when /hash(es)?\b|4/ @hash = RubyDictionary::Klass.list[3] RubyDictionary::Scraper.scrape_klass(@hash) (@hash) when /numeric(s)?\b|5/ @num = RubyDictionary::Klass.list[4] RubyDictionary::Scraper.scrape_klass(@num) (@num) when /proc(s)?\b|6/ @prok = RubyDictionary::Klass.list[5] RubyDictionary::Scraper.scrape_klass(@prok) (@prok) when /range(s)?\b|7/ @range = RubyDictionary::Klass.list[6] RubyDictionary::Scraper.scrape_klass(@range) (@range) when /string(s)?\b|8/ @string = RubyDictionary::Klass.list[7] RubyDictionary::Scraper.scrape_klass(@string) (@string) when /symbol(s)?\b|9/ @symbol = RubyDictionary::Klass.list[8] RubyDictionary::Scraper.scrape_klass(@symbol) (@symbol) else if input != "exit" puts "I'm sorry, I didn't get that. Please enter a Class or type 'list' or type 'exit'" end end end def goodbye puts "Happy Coding!!!" end end |
#scrape_slow_classes ⇒ Object
14 15 16 17 18 19 |
# 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 |