class CLI

> Handles all interfacing with our user

Attributes

articles[RW]

> Articles array accessor

Public Instance Methods

display_article(article) click to toggle source

> Displays all of the article information for the user to read

# File lib/crowder_news/cli.rb, line 83
def display_article(article)
  input = nil
  puts "\n#{article.title}"
  puts "\nAuthor: #{article.author} on #{article.date}: "
  puts "\n\t#{article.body}"
  if article.youtube_links
    puts "\nYoutube Links:"
    article.youtube_links.each{ |link|
      puts link
    }
  end
  puts 'Press any key to find another article or "exit" to exit.'
  input = gets.strip.downcase
  if input == "exit"
    goodbye
  else
    list_articles
  end
end
display_list(articles) click to toggle source

> Displays a list of articles for the user

# File lib/crowder_news/cli.rb, line 50
def display_list(articles)
  articles.each.with_index(1) do |article, index|
    puts "#{index}. #{article.title}"
    if(article.excerpt != "")
      puts "\t#{article.excerpt[0...98]}..."
    end
  end
  puts ""
end
goodbye() click to toggle source

> Tells the user goodbye and exits program

# File lib/crowder_news/cli.rb, line 106
def goodbye
  puts "\nSee you next time!"
end
initiate() click to toggle source

> Intiates the program, scrapes the website and welcomes the user

# File lib/crowder_news/cli.rb, line 9
def initiate
  Scraper.initiate_scrape
  puts "Welcome to Today on Crowder!"
  list_articles
end
list_articles() click to toggle source

> Lists the articles according to the user's preferences

# File lib/crowder_news/cli.rb, line 18
def list_articles
  input = nil
  choices = 'Choose one: recent, featured, or both. To exit type "exit".'
  puts choices
  input = gets.strip.downcase
  puts ""
  if input == "recent"
    puts "Recent Articles: "
    @articles = Article.recents
    display_list(@articles)
    menu
  elsif input == "featured"
    puts "Featured Articles: "
    @articles = Article.featured
    display_list(@articles)
    menu
  elsif input == "both"
    puts "All articles: "
    @articles = Article.all
    display_list(@articles)
    menu
  elsif input == "exit"
    goodbye
  else
    list_articles
  end

end
menu() click to toggle source

> Gives the user the options to view articles, switch lists, or exit the program