Class: Catpedia::CLI

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

Instance Method Summary collapse

Instance Method Details

#list_cats_in_range(a, b) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object

shows detail for specific cat



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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_rangesObject

puts ranges of cats for user to select



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

#startObject



3
4
5
6
7
8
9
# 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