class Catpedia::CLI
Public Instance Methods
list_cats_in_range(a,b)
click to toggle source
# File lib/catpedia/cli.rb, line 35 def list_cats_in_range(a,b) puts "" puts 'Please select a cat breed:' puts "" cats = Catpedia::Cat.all[a,b] cats.each.with_index do |cat, index| puts "#{index + 1}. #{cat.name}" #puts the individual cat breeds for a given range within all cats end input = gets.strip #user selects a single cat index = input.to_i - 1 cat = cats[index] #the cat instance from the range of cats array list_details(cat) end
list_details(cat)
click to toggle source
# File lib/catpedia/cli.rb, line 50 def list_details(cat) #shows detail for specific cat puts "\n\rWhat would you like to know more about the #{cat.name}?" puts "" puts "1. Summary" puts "2. History" puts "3. Personality" puts "4. Health" puts "5. Grooming" puts "...or 's' to start over, 'q' to quit" input = gets.strip case input when '1' puts "\n\r--------SUMMARY--------\n\r" puts "#{cat.summary}" when '2' puts "\n\r--------HISTORY--------\n\r" puts "#{cat.history}" when '3' puts "\n\r--------PERSONALITY--------\n\r" puts "#{cat.personality}" when '4' puts "\n\r--------HEALTH--------\n\r" puts "#{cat.health}" when '5' puts "\n\r--------GROOMING--------\n\r" puts "#{cat.grooming}" when 's' return list_ranges #go back to start of program when 'q' exit end list_details(cat) end
list_ranges()
click to toggle source
# File lib/catpedia/cli.rb, line 11 def list_ranges #puts ranges of cats for user to select puts "" puts 'Which range of cat breeds would you like to browse? Enter a number:' puts "" puts "1. '#{Catpedia::Cat.all[0].name}' through '#{Catpedia::Cat.all[9].name}'" puts "2. '#{Catpedia::Cat.all[10].name}' through '#{Catpedia::Cat.all[19].name}'" puts "3. '#{Catpedia::Cat.all[20].name}' through '#{Catpedia::Cat.all[29].name}'" puts "4. '#{Catpedia::Cat.all[30].name}' through '#{Catpedia::Cat.all[39].name}'" puts "5. '#{Catpedia::Cat.all[40].name}' through '#{Catpedia::Cat.all.last.name}'" input = gets.strip #gets the user selection and lists cats if input == '1' list_cats_in_range(0,10) elsif input == '2' list_cats_in_range(10,10) elsif input == '3' list_cats_in_range(20,10) elsif input == '4' list_cats_in_range(30,10) elsif input == '5' list_cats_in_range(40,10) end end
start()
click to toggle source
# File lib/catpedia/cli.rb, line 3 def start puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" puts 'Welcome to Catpedia. Please wait a few seconds for the program to load...' puts "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" Catpedia::Scraper.scrape_cats list_ranges end