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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/blue_cross_pets/cli.rb', line 54

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) || @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
      puts "Paw-fect choice!".light_white
      list_additional_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
33
34
# 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.create_dogs
        list_all
        choose_animal
      when "cats"
        @current_animal = "cat"
        puts "----------------------------- Our cats: -----------------------------".blue
        BlueCrossPets::Cat.create_cats
        list_all
        choose_animal
      when "exit"
      else
        puts "Sorry, we didn't understand that!".red
        choose_animal_type
    end
end

#goodbyeObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/blue_cross_pets/cli.rb', line 104

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

#list_additional_info(input) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/blue_cross_pets/cli.rb', line 78

def list_additional_info(input)
  index = input.to_i - 1

  if @current_animal == "dog" && input.to_i.between?(1, BlueCrossPets::Dog.all.length)
    pet_choice = BlueCrossPets::Dog.all[index]
  elsif @current_animal == "cat" && input.to_i.between?(1, BlueCrossPets::Cat.all.length)
    pet_choice = BlueCrossPets::Cat.all[index]
  end 

  pet_choice.get_more_info 
  
  puts "----------------------------- All about #{pet_choice.name} -----------------------------".blue
  puts "Age: ".light_white + "#{pet_choice.age}"
  puts "Gender: ".light_white + "#{pet_choice.gender}"
  puts "Availability: ".light_white + "#{pet_choice.availability}"
  puts "Breed & colour: ".light_white + "#{pet_choice.breed_and_colour}"

  if pet_choice.can_live_with
    puts "Can live with: ".light_white + "#{pet_choice.can_live_with}"
  end

  puts "Bio: ".light_white + "#{pet_choice.bio}"
  puts "Animal reference number: ".light_white + "#{pet_choice.reference}"
  puts "Visit my page: ".light_white + "#{pet_choice.profile_url}"
end

#list_allObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/blue_cross_pets/cli.rb', line 36

def list_all
  if @current_animal == "dog"
    BlueCrossPets::Dog.all.each.with_index(1) do |dog, index|
      puts "#{index}. ".blue + "#{dog.name} - #{dog.breed} - #{dog.gender} - #{dog.age} - #{dog.availability}"
    end

  elsif @current_animal == "cat"
    BlueCrossPets::Cat.all.each.with_index(1) do |dog, index|
      puts "#{index}. ".blue + "#{dog.name} - #{dog.breed} - #{dog.gender} - #{dog.age} - #{dog.availability}"
    end
  end 
end

#number?(input) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/blue_cross_pets/cli.rb', line 49

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