Class: CatsToAdopt::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cats_to_adopt/CLI.rb

Constant Summary collapse

BASE_PATH =
"https://la.bestfriends.org/get-involved/adopt/"

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
# File 'lib/cats_to_adopt/CLI.rb', line 5

def call
  intro_message
  make_cats
  list_cats
  menu
  goodbye
end

#goodbyeObject



52
53
54
# File 'lib/cats_to_adopt/CLI.rb', line 52

def goodbye
  puts "\nGoodbye!"
end

#intro_messageObject



13
14
15
16
17
18
# File 'lib/cats_to_adopt/CLI.rb', line 13

def intro_message
  puts "\n-----------------------------"
  puts "| Welcome to Cats to Adopt! |"
  puts "-----------------------------\n\n"
  puts "Retrieving cat info..."
end

#list_catsObject



24
25
26
# File 'lib/cats_to_adopt/CLI.rb', line 24

def list_cats
  CatsToAdopt::Cat.print_cats
end

#make_catsObject



20
21
22
# File 'lib/cats_to_adopt/CLI.rb', line 20

def make_cats
  CatsToAdopt::Scraper.scrape_main_page(BASE_PATH + 'pets?field_animal_species_tid_selective=958')
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cats_to_adopt/CLI.rb', line 28

def menu
  input =  ""

  while input != "exit"
    puts "\nEnter the number of the cat you would like more info on."
    puts "Type list to list all cats or exit to exit the program."
    input = gets.strip

    cats = CatsToAdopt::Cat.all

    if input.to_i > 0 && input.to_i < cats.size + 1
      cat_in_question = cats[input.to_i - 1]
      attributes = CatsToAdopt::Scraper.scrape_profile_page(BASE_PATH + 'pet/' + cat_in_question.id)
      cat_in_question.add_cat_attributes(attributes)
      cat_in_question.print_cat_info
    elsif input == "list"
      list_cats
    elsif input == "exit"
      puts "\nClosing program ..."
    else
      puts "Please enter the number of a cat, list, or exit."
    end
  end

  def goodbye
    puts "\nGoodbye!"
  end
end