Class: WikihowTechTopics::CLI
- Inherits:
-
Object
- Object
- WikihowTechTopics::CLI
- Defined in:
- lib/wikihow_tech_topics/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #content_parser_multiple_methods(content) ⇒ Object
- #get_content_for_user_multiple_methods ⇒ Object
- #get_content_for_user_single_method ⇒ Object
- #get_title_for_user ⇒ Object
- #list_titles ⇒ Object
- #option ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
Instance Method Details
#call ⇒ Object
7 8 9 |
# File 'lib/wikihow_tech_topics/cli.rb', line 7 def call start end |
#content_parser_multiple_methods(content) ⇒ Object
76 77 78 79 80 |
# File 'lib/wikihow_tech_topics/cli.rb', line 76 def content_parser_multiple_methods(content) content.each.with_index(1) do |method, method_num| puts "Method/Part #{method_num}. #{method}" end end |
#get_content_for_user_multiple_methods ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wikihow_tech_topics/cli.rb', line 54 def get_content_for_user_multiple_methods newly_scraped_for_content = WikihowTechTopics::Scraper.scraped_content_array newly_scraped_for_content.each.with_index(1) do |final_content, i| case when @user_input == i && final_content.size >= 2 content_parser_multiple_methods(final_content) option end end end |
#get_content_for_user_single_method ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wikihow_tech_topics/cli.rb', line 65 def get_content_for_user_single_method newly_scraped_for_content = WikihowTechTopics::Scraper.scraped_content_array newly_scraped_for_content.each.with_index(1) do |final_content, i| case when @user_input == i && final_content.size == 1 puts final_content option end end end |
#get_title_for_user ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wikihow_tech_topics/cli.rb', line 37 def get_title_for_user @user_input = gets.to_i @scraped_titles_array.each.with_index(1) do |title, i| case when @user_input == i puts "" puts "" puts title puts "" puts "" puts "Your article ... " puts "" puts "" end end end |
#list_titles ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wikihow_tech_topics/cli.rb', line 26 def list_titles @scraped_titles_array = [] WikihowTechTopics::WikihowTechTopicModel.all WikihowTechTopics::WikihowTechTopicModel.all.each.with_index(1) do |title, i| @scraped_titles_array << title.title puts "#{i}. #{title.title}" end puts "" puts "" end |
#option ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/wikihow_tech_topics/cli.rb', line 82 def option puts "" puts "" puts "Would you like to read another article? (type y for \"yes\" and n for \"no\")" read_again_input = gets.strip if read_again_input == "y" start else puts "" puts "" puts "Goodbye for now!" puts "" puts "" end end |
#run ⇒ Object
19 20 21 22 23 24 |
# File 'lib/wikihow_tech_topics/cli.rb', line 19 def run list_titles get_title_for_user get_content_for_user_multiple_methods get_content_for_user_single_method end |
#start ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/wikihow_tech_topics/cli.rb', line 11 def start puts "Welcome to Wikihow Tech Topics!" puts "" puts "Review the list of articles below,\ntype the number of the article\nthat you wish to read, and hit return." puts "" run end |