Class: BlueCrossPets::CLI

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

Overview

CLI Controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_animalObject

Returns the value of attribute current_animal.



5
6
7
# File 'lib/blue_cross_pets/cli.rb', line 5

def current_animal
  @current_animal
end

Instance Method Details

#callObject



7
8
9
10
11
# File 'lib/blue_cross_pets/cli.rb', line 7

def call
  puts "Woof! Welcome to the ".bold +  "Blue Cross Pet Shelter!".light_white.on_blue.bold + " We heard you're interested in adopting a furry friend.".bold
  choose_animal_type
  goodbye
end

#choose_animalObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/blue_cross_pets/cli.rb', line 39

def choose_animal
  puts "Please enter the number of the pet you'd like more info on, or type '" + "menu".light_white + "' to choose a different animal, or '" + "exit".light_white + "' to exit."
  input = gets.strip.downcase

  if number?(input) == true
    if @current_animal == "dog" && input.to_i.between?(1, BlueCrossPets::Dog.all.length)
      puts "Paw-fect choice!".light_white
      BlueCrossPets::Dog.get_more_info(input)
    elsif @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
      puts "Paw-fect choice!".light_white
      BlueCrossPets::Cat.get_more_info(input)
    else
      puts "Sorry, we didn't understand that!".red
    end
    choose_animal
  else
    case input
    when "menu"
      choose_animal_type
    when "exit"
    else
      puts "Sorry, we didn't understand that!".red
      choose_animal
    end
  end
end

#choose_animal_typeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blue_cross_pets/cli.rb', line 13

def choose_animal_type
  puts "To learn more about our adoptable dogs, type '" + "dogs".light_white + "'. To learn more about our adoptable cats, type '" + "cats".light_white + "'. To exit, type '" + "exit".light_white + "'."
  input = gets.strip.downcase
    case input
      when "dogs"
        @current_animal = "dog"
        puts "----------------------------- Our dogs: -----------------------------".blue
        BlueCrossPets::Dog.scrape_dogs
        choose_animal
      when "cats"
        @current_animal = "cat"
        puts "----------------------------- Our cats: -----------------------------".blue
        BlueCrossPets::Cat.scrape_cats
        choose_animal
      when "exit"
      else
        puts "Sorry, we didn't understand that!".red
        choose_animal_type
    end
end

#goodbyeObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/blue_cross_pets/cli.rb', line 66

def goodbye
  puts "Thanks for stopping by! Have a great day!".blue.bold
  text = "     h  h\n   h(\")(\")h\n  (\"),--.(\")\n   :\"    \";\n   `.____,'\n   TEXT\n  puts text.light_white\nend\n"

#number?(input) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/blue_cross_pets/cli.rb', line 34

def number?(input)
  input = input.to_s unless input.is_a? String
  !!(/\A[+-]?\d+\z/.match(input))
end