Class: TechNews::CLI
- Inherits:
-
Object
- Object
- TechNews::CLI
- Defined in:
- lib/tech_news/cli.rb
Overview
CLI Controller
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
4 5 6 7 8 |
# File 'lib/tech_news/cli.rb', line 4 def call list_articles goodbye end |
#goodbye ⇒ Object
43 44 45 |
# File 'lib/tech_news/cli.rb', line 43 def goodbye puts "Check in again for more tech articles!" end |
#list_articles ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/tech_news/cli.rb', line 10 def list_articles puts " " puts "The Latest in Tech News:" puts " " @articles = TechNews::Article.all @articles.each.with_index(1) do |article, i| puts "#{i}. #{article.title}" end end |
#menu ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tech_news/cli.rb', line 20 def input = nil while input != "exit" puts " " puts "Enter the number of the article you'd like to read, type list to see the list of articles again, or type exit:" puts " " input = gets.strip.downcase if input.to_i > 0 the_article = @articles[input.to_i - 1] puts "" `open #{the_article.url}` puts "#{input}. #{the_article.title}" # puts "#{the_article.url}" puts " " elsif input == "list" list_articles else puts "Not sure what you want, type list or exit." unless input == "exit" end end end |