Class: TellyReviews::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
# File 'lib/telly_reviews/cli.rb', line 3

def call
  puts ""
  puts "Welcome to Telly Reviews"
  puts "---------------------------------"
  TellyReviews::Scraper.make_list
  start
end


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/telly_reviews/cli.rb', line 48

def print_details(review)
  puts "---------------------------------"
  puts "#{review.title}"
  puts ""
  puts "By #{review.author}"
  puts "#{review.date}"
  puts "Twitter: #{review.author_twitter}"
  puts "---------------------------------"
  puts ""
  puts "#{review.body}"
  puts "---------------------------------"
end


37
38
39
40
41
# File 'lib/telly_reviews/cli.rb', line 37

def print_list
  TellyReviews::Review.all.each.with_index(1) do |review, index|
    puts "#{index}. #{review.title} by #{review.author}"
  end
end


43
44
45
46
# File 'lib/telly_reviews/cli.rb', line 43

def print_review(review)
  review.review_details
  print_details(review)
end

#startObject



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
# File 'lib/telly_reviews/cli.rb', line 11

def start 
  puts ""
  print_list
  puts "---------------------------------"
  puts ""
  puts "Enter number to see article:"
  input = gets.strip

  review = TellyReviews::Review.find(input.to_i)
  print_review(review)
  puts ""
  puts "Type 'open' to open this article in your web browser."
  puts "Would you like to read another review? (y/n)"
  input = gets.strip.downcase
  if input == 'y'
    puts ""
    start
  elsif input == 'open'
    system("open", "#{review.url}")
    start
  else
    puts "Please come back soon for more updated reviews!"
    exit
  end
end