Module: HeadlineChoice

Included in:
Headline
Defined in:
lib/nfl_top_stories/concerns/headline_choice.rb

Instance Method Summary collapse

Instance Method Details

#get_choice(source) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nfl_top_stories/concerns/headline_choice.rb', line 24

def get_choice(source)
  puts "\033[0;36mWhich story would you like to read?\033[0m"
  puts "0. Back to the main menu"
  @headlines.each.with_index(1) do |headline, i|
    puts "#{i}. #{headline.title}"
  end

  case source
  when "espn"
    get_source = "espn_stories"
  when "nfl"
    get_source = "nfl_stories"
  when "cbs"
    get_source = "cbs_stories"
  when "fox"
    get_source = "fox_stories"
  when "usa"
    get_source = "usa_stories"
  end

  input = gets.strip.downcase
  if input == "0"
    puts ""
    CLI.new.call
  elsif input == "1"
    Story.send(get_source, @headlines[0].url)
  elsif input == "2"
    Story.send(get_source, @headlines[1].url)
  elsif input == "3"
    Story.send(get_source, @headlines[2].url)
  elsif input == "4"
    Story.send(get_source, @headlines[3].url)
  elsif input == "5"
    Story.send(get_source, @headlines[4].url)
  elsif input == "6"
    Story.send(get_source, @headlines[5].url)
  else
    puts ""
    puts "\033[0;33mInvalid entry...\033[0m"
    get_choice(source)
  end
end

#get_headlines(source) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/nfl_top_stories/concerns/headline_choice.rb', line 3

def get_headlines(source)
  @headlines = []
  case source.to_s
  when "espn"
    self.scrape_espn
    get_choice("espn")
  when "nfl"
    self.scrape_nfl
    get_choice("nfl")
  when "cbs"
    self.scrape_cbs
    get_choice("cbs")
  when "fox"
    self.scrape_fox
    get_choice("fox")
  when "usa"
    self.scrape_usa
    get_choice("usa")
  end
end