Class: SportHeadlines::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sport_headlines/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
6
7
# File 'lib/sport_headlines/cli.rb', line 2

def call
  puts "Welcome to the Sports Headlines Aggregator."
  puts ""
  SportHeadlines::Site.create_sites_from_hash
  start
end

#list_sitesObject



32
33
34
35
36
# File 'lib/sport_headlines/cli.rb', line 32

def list_sites
  SportHeadlines::Site.all.each_with_index do |site, index|
    puts "#{index +1}. #{site.site_name}"
  end
end

#startObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sport_headlines/cli.rb', line 9

def start
  sites = SportHeadlines::Site.all
  scraper = SportHeadlines::Scraper
  puts ""
  input = nil
  while input != 'exit'
    puts "Please select a site - by number you would like to view the top headlines from. Enter exit to end the program"
    puts ""
    list_sites
    puts ""
    input = gets.strip
    if input.to_i.between?(1,sites.size)
      scraper.scrape_site_headlines(sites[input.to_i-1])
      puts "Select an article to read its content."
      puts ""
      sites[input.to_i-1].list_articles
      article_input = gets.strip
      scraper.scrape_article(sites[input.to_i-1].articles[article_input.to_i - 1])
      sites[input.to_i-1].articles[article_input.to_i - 1].print_content
    end
  end
end