Class: BbcNewsCliGem::CLI
- Inherits:
-
Object
- Object
- BbcNewsCliGem::CLI
- Defined in:
- lib/bbc_news_cli_gem/cli.rb
Instance Attribute Summary collapse
-
#web_page ⇒ Object
readonly
Returns the value of attribute web_page.
Instance Method Summary collapse
- #call ⇒ Object
- #check_for_open(article) ⇒ Object
- #get_article(input) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #main_loop ⇒ Object
- #welcome ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
5 6 7 8 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 5 def initialize front_page_scraper = BbcNewsCliGem::Scraper.new(BbcNewsCliGem::RootAddress+"/news") @web_page = front_page_scraper.scrape_front_page end |
Instance Attribute Details
#web_page ⇒ Object (readonly)
Returns the value of attribute web_page.
3 4 5 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 3 def web_page @web_page end |
Instance Method Details
#call ⇒ Object
10 11 12 13 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 10 def call welcome main_loop end |
#check_for_open(article) ⇒ Object
36 37 38 39 40 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 36 def check_for_open(article) puts "Do you want to open the article in the browser? (y/n)" input = gets.chomp article.open if input == "y" end |
#get_article(input) ⇒ Object
31 32 33 34 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 31 def get_article(input) article_index = input.split(" ").last.to_i - 1 web_page.articles[article_index] end |
#help ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 15 def help seperator = "------------------------------------------" puts seperator puts "You can use any of the following commands:" puts "'help' - get options" puts "'articles' - shows a list of all articles" puts "'article <some number>' - opens the article of the number specified" puts "'exit' - quits this gem" puts seperator end |
#main_loop ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 42 def main_loop puts "What would you like to do?" input = gets.chomp case input when "help" help main_loop when "articles" web_page.display_articles main_loop when "exit" puts "Whatevery, I didn't want you to read the news anyway. " when /^article/ article = get_article(input) article.display check_for_open(article) main_loop else puts "I'm sorry, I don't know what you're saying" main_loop end end |
#welcome ⇒ Object
26 27 28 29 |
# File 'lib/bbc_news_cli_gem/cli.rb', line 26 def welcome puts "Hello! Welcome to the BBC News CLI Gem" help end |