Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #display_article_details(index) ⇒ Object
- #display_articles ⇒ Object
- #make_articles(page_url = "https://longreads.com/picks") ⇒ Object
- #menu ⇒ Object
- #page_url(page_num) ⇒ Object
- #run ⇒ Object
Instance Method Details
#call ⇒ Object
6 7 8 9 10 |
# File 'lib/cli.rb', line 6 def call puts "Welcome to the longform browsing Ruby Gem CLI!" puts "" run end |
#display_article_details(index) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cli.rb', line 34 def display_article_details(index) puts "----------------------".colorize(:green) puts "#{Article.all[index].title}".colorize(:blue) puts " Description:".colorize(:light_blue) + " #{Article.all[index].description}" puts " Author(s):".colorize(:light_blue) + " #{Article.all[index].}" puts " Source:".colorize(:light_blue) + " #{Article.all[index].source}" puts " Published:".colorize(:light_blue) + " #{Article.all[index].date}" puts " Length:".colorize(:light_blue) + " #{Article.all[index].length}" puts "" puts " Link:".colorize(:light_blue) + " #{Article.all[index].url}" puts "----------------------".colorize(:green) end |
#display_articles ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/cli.rb', line 25 def display_articles Article.all.each_with_index do |article, index| puts "#{index + 1}. #{article.title}\n".colorize(:blue) puts "#{article.description}" puts "----------------------".colorize(:green) end end |
#make_articles(page_url = "https://longreads.com/picks") ⇒ Object
19 20 21 22 23 |
# File 'lib/cli.rb', line 19 def make_articles(page_url = "https://longreads.com/picks") Article.all.clear articles_array = Scraper.scrape_index_page(page_url) Article.create_from_collection(articles_array) end |
#menu ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cli.rb', line 48 def puts "Type \"Search\" to select a page of articles, the number of an article to view its details, or \"exit\" to leave the CLI." input = gets.chomp if input.downcase == "search" puts "Please enter the page number you would like to view." page_num = gets.chomp.to_i make_articles(page_url(page_num)) display_articles elsif (1..10).include?(input.to_i) display_article_details(input.to_i - 1) elsif input == "exit" puts "Thank you for reading today!" @active = false else end end |
#page_url(page_num) ⇒ Object
66 67 68 |
# File 'lib/cli.rb', line 66 def page_url(page_num) "https://longreads.com/picks" + "/?page=#{page_num}" end |
#run ⇒ Object
12 13 14 15 16 17 |
# File 'lib/cli.rb', line 12 def run @active = true while @active end end |