Class: UrbanNews::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



10
11
12
13
14
15
16
# File 'lib/urban_news/cli.rb', line 10

def call
  UrbanNews::Scraper.make_stories
  puts " "
  puts "*** Welcome to Urban News! Read stories on urban issues affecting Houston and the U.S. ***"
  puts " "
  start
end


51
52
53
54
55
56
57
58
59
60
# File 'lib/urban_news/cli.rb', line 51

def print_title_and_summary
  UrbanNews::Story.all.each.with_index do |story, index|
    puts " "
    puts "Story# #{index+1}. #{story.title}"
    puts " "
    puts "#{story.summary}"
    puts " "
    puts "----------------------------------------------------"
  end
end


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/urban_news/cli.rb', line 62

def print_url_content_credit(user_input)
  puts " "
  puts "Source: #{user_input.url}"
  puts " "
  puts "#{user_input.title}"
  puts " "
  puts "#{user_input.credit}"
  puts " "
  puts "#{user_input.content}"
  puts " " 
end

#startObject



18
19
20
21
22
23
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
# File 'lib/urban_news/cli.rb', line 18

def start
  puts " "
  puts "-------------Here are our Latest Posts:-------------"
  puts " "
  print_title_and_summary  
  puts " "
  puts "Which story would you like to read? Enter the number of the story."
  input = gets.strip
    case input
    when "1".."15"
      story = UrbanNews::Story.find(input.to_i)
      print_url_content_credit(story)
    else 
      puts " "
      puts "***Try again!***"
      start
    end  
  puts " "
  puts "Would you like to read another story? Y/N."
  puts " "
  input = gets.strip
    if input.downcase == "y"
      start
    elsif input.downcase == "n"
      puts "Thank you for reading!"
      exit
    else
      puts " "
      puts "***Try again!***"
      start
    end 
end