Class: DrummingNews::CLI
- Inherits:
-
Object
- Object
- DrummingNews::CLI
- Defined in:
- lib/drummingnews_cli_scraper/cli.rb
Instance Attribute Summary collapse
-
#articles ⇒ Object
Returns the value of attribute articles.
-
#current_magazine ⇒ Object
Returns the value of attribute current_magazine.
Instance Method Summary collapse
- #call ⇒ Object
- #choose_article ⇒ Object
- #choose_mag ⇒ Object
- #display_article(article_choice) ⇒ Object
- #list_articles ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#articles ⇒ Object
Returns the value of attribute articles.
2 3 4 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 2 def articles @articles end |
#current_magazine ⇒ Object
Returns the value of attribute current_magazine.
2 3 4 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 2 def current_magazine @current_magazine end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 12 def call choose_mag list_articles choose_article end |
#choose_article ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 52 def choose_article puts "Which one would you like to view? Enter 'back' to go to the main menu, or 'exit' to quit" article_choice = gets.strip until article_choice.to_i.between?(1, 10) || article_choice.downcase == "back" || article_choice.downcase == "exit" do ###Probably gonna need to change condition to a .length or something puts "Please enter a valid article number or 'back'" article_choice = gets.strip end if article_choice.downcase == "back" puts "" call elsif article_choice.downcase == "exit" exit else display_article(article_choice.to_i) end end |
#choose_mag ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 18 def choose_mag puts "Which site's articles would you like to view?" puts "1. Modern Drummer" puts "2. DRUM!" puts "3. Rhythm Magazine" puts "Or 'exit' to quit" mag_choice = "" mag_choice = gets.strip case mag_choice.downcase when "1" @articles = Modern_drummer.articles ###Find magazine by title and get articles @current_magazine = Modern_drummer when "2" @articles = DRUM.articles @current_magazine = DRUM when "3" @articles = Rhythm.articles @current_magazine = Rhythm when "exit" exit else puts "Please enter 1-3 or 'exit'" choose_mag end end |
#display_article(article_choice) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 69 def display_article(article_choice) article_url = @current_magazine.find(article_choice).url article_content = @scraper.scrape_article(article_url, @current_magazine) puts article_content call end |
#list_articles ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 44 def list_articles puts "\n------------------------------------------" @articles.each_with_index do |article, index| puts "#{index + 1}. #{article.title}" end puts "------------------------------------------\n" end |
#start ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/drummingnews_cli_scraper/cli.rb', line 4 def start @scraper = DrummingNews::Scraper.new #Instansiate scraper @scraper.scrape_md @scraper.scrape_drum @scraper.scrape_rhythm call end |