Class: TopHeadlines::CLI
- Inherits:
-
Object
- Object
- TopHeadlines::CLI
- Defined in:
- lib/top-headlines/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #invalid_entry ⇒ Object
- #list_all_headlines ⇒ Object
- #list_all_headlines_banner ⇒ Object
- #list_headlines_from_source ⇒ Object
- #menu ⇒ Object
- #news_sources ⇒ Object
- #news_sources_banner ⇒ Object
- #open_headline_in_browser ⇒ Object
- #request_input_full_menu ⇒ Object
- #time ⇒ Object
- #welcome_banner ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 |
# File 'lib/top-headlines/cli.rb', line 3 def call news_sources goodbye end |
#goodbye ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/top-headlines/cli.rb', line 114 def goodbye system "clear" puts "\nThanks for visiting – see you next time!" puts " \n\n ```-. \n `.-:::- ```````` \n `.-:::::---. `..----------..` \n -:::::::-` `.-----------------. \n `-::::::` `.---------------------` \n `-:::-- `------/o:------:o/------` \n .. -------+o/------:o+-------` \n `..` `--------------------------. \n `..---------------------------. \n `--------------------------. \n .-----:yo:------:oy:------ \n `.------+yyooooyyo:------` \n .--------::/:--------. \n `.----------------.` \n ``..------...` \n\n\n Image: VectorStock (https://www.vectorstock.com/royalty-free-vector/bye-goodbye-vector-6122218)\n ASCII Image Conversion: Patrik Roos (http://www.text-image.com/convert/ascii.html)\n\n TopHeadlines Gem made by Zach Newburgh (http://www.zachnewburgh.com/)\n Copyright \u00A9 2016 Zach Newburgh\n \n DOC\n\nend\n" |
#invalid_entry ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/top-headlines/cli.rb', line 106 def invalid_entry puts "\n=> INVALID SELECTION: #{request_input_full_menu}" sleep(1) news_sources print "YOUR SELECTION: " end |
#list_all_headlines ⇒ Object
63 64 65 |
# File 'lib/top-headlines/cli.rb', line 63 def list_all_headlines TopHeadlines::Source.list_all_headlines end |
#list_all_headlines_banner ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/top-headlines/cli.rb', line 55 def system "clear" puts " -------------------------------" puts "| TOP HEADLINES & BREAKING NEWS |" puts " -------------------------------" time end |
#list_headlines_from_source ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/top-headlines/cli.rb', line 77 def list_headlines_from_source system "clear" puts "\n*** #{@input} ***" time TopHeadlines::Source.scrape_headlines(@input)[0,5].each_with_index {|headline, index| puts "#{index + 1}. #{headline}"} puts "\n" end |
#menu ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/top-headlines/cli.rb', line 10 def puts "Which source do you want to view? Alternatively, type 'all' to view all headlines or 'exit' to exit!" print "YOUR SELECTION: " @input = nil while @input != "EXIT" && @num != "EXIT" @input = gets.strip.upcase if @input == "ALL" list_all_headlines puts print "YOUR SELECTION: " elsif @input == "SOURCES" news_sources puts print "YOUR SELECTION: " elsif TopHeadlines::Source.all.keys.include?(@input) list_headlines_from_source open_headline_in_browser elsif @input != "EXIT" invalid_entry else nil end end end |
#news_sources ⇒ Object
50 51 52 53 |
# File 'lib/top-headlines/cli.rb', line 50 def news_sources TopHeadlines::Source.all.keys.sort.each {|source| puts "*** #{source} ***"} puts "\n" end |
#news_sources_banner ⇒ Object
71 72 73 74 75 |
# File 'lib/top-headlines/cli.rb', line 71 def puts "\n" puts "NEWS SOURCES" puts "------------" end |
#open_headline_in_browser ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/top-headlines/cli.rb', line 85 def open_headline_in_browser puts "Select headline number to open the full article in the browser." print "YOUR SELECTION: " @num = gets.strip.upcase while @num.to_i.between?(1,5) headline = TopHeadlines::Source.scrape_headlines(@input)[@num.to_i-1] puts "\n=> You selected the #{@num.to_i.ordinalize} headline: '#{headline}'." puts "=> Opening..." sleep(2) url = TopHeadlines::Source.scrape_urls(@input)[@num.to_i-1] system("open", url) sleep(1) puts "\nSelect another headline number to open full article in the browser." print "YOUR SELECTION: " @num = gets.strip.upcase end invalid_entry if @num != "EXIT" end |
#request_input_full_menu ⇒ Object
67 68 69 |
# File 'lib/top-headlines/cli.rb', line 67 def "Select a source, type 'sources' to view sources, type 'all' to view all headlines, or type 'exit' to exit." end |
#time ⇒ Object
45 46 47 48 |
# File 'lib/top-headlines/cli.rb', line 45 def time puts "Reporting live as of #{Time.now.strftime("%l:%M %p %Z on %a, %b #{Time.now.strftime("%e").to_i.ordinalize}, %Y")}:" puts "\n" end |
#welcome_banner ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/top-headlines/cli.rb', line 37 def system "clear" puts " --------------------------- " puts "| WELCOME TO TOP HEADLINES! |" puts " --------------------------- " time end |