class BestNovels::CLI

Public Instance Methods

call() click to toggle source
# File lib/best_novels/cli.rb, line 2
def call
  puts "Welcome to The Guardian's List of 100 Best Novels!".colorize(:blue)
  @input = ""
  until @input == "exit"
  get_novels
  list_novels
  get_user_novel
  what_next
end
goodbye
end
get_novels() click to toggle source
# File lib/best_novels/cli.rb, line 15
def get_novels
  @novels = BestNovels::Novel.all
end
get_user_novel() click to toggle source
# File lib/best_novels/cli.rb, line 29
def get_user_novel
  chosen_novel = gets.strip.to_i
  show_details_for(chosen_novel) if valid_input(chosen_novel, @novels)

end
goodbye() click to toggle source
# File lib/best_novels/cli.rb, line 61
def goodbye
  puts "Thanks! Goodbye".colorize(:red)
end
list_novels() click to toggle source
# File lib/best_novels/cli.rb, line 19
def list_novels
  puts ''
  puts 'Choose a novel to read a review from The Guardian.'.colorize(:blue)
  puts ''

@novels.each.with_index(1) do |novel, index|
    puts "#{index}. #{novel.title}"
  end
end
show_details_for(chosen_novel) click to toggle source
# File lib/best_novels/cli.rb, line 41
def show_details_for(chosen_novel)
  novel = @novels[chosen_novel - 1]
  novel.get_novel_details
  puts ""
  puts "The Guardian's Review of ".colorize(:blue) +
   "#{novel.title}".colorize(:blue).bold
  puts ""
  puts novel.review
  puts ""
  puts "Read the full review:".colorize(:blue)
  puts "#{novel.url}".colorize(:blue).underline
end
valid_input(input, data) click to toggle source
# File lib/best_novels/cli.rb, line 35
def valid_input(input, data)
  input.to_i <= data.length && input.to_i > 0
end
what_next() click to toggle source
# File lib/best_novels/cli.rb, line 54
def what_next
  puts ""
  puts ""
  puts "Are you done? Type 'exit' to exit or press any key to view the full list of novels.".colorize(:blue)
  @input = gets.strip
 end