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



38
39
40
41
42
# File 'lib/sport_headlines/cli.rb', line 38

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
31
32
33
34
35
36
# 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)
      site = SportHeadlines::Site.find(input)
      site.scrape_headlines!
      # scraper.scrape_site_headlines(sites[input.to_i-1])

      puts "Select an article to read its content."
      puts ""
      site.list_articles
      article_input = gets.strip
      article = site.scrape_article(article_input) # preps the article, and returns the instance of the article
      # scraper.scrape_article(sites[input.to_i-1].articles[article_input.to_i - 1])
      article.print_content

      # sites[input.to_i-1].articles[article_input.to_i - 1].print_content
    end
  end
end