Class: SeaLife::CLI

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

Instance Method Summary collapse

Instance Method Details

#animal_menu(animal) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sea_life/cli.rb', line 88

def animal_menu(animal)
  input = gets.strip.downcase

  if input == "more"
    puts ""
    puts "#{animal.longer_desc}"
    puts ""
    puts "Please enter BACK, MENU, or EXIT."
    animal_menu(animal)
  elsif input == "back"
    list_animals(animal.category)
  elsif input == "menu"
    list_categories
  elsif input == "exit"
    goodbye
  else
    puts "Invalid input. Please enter MORE, BACK, MENU, or EXIT."
    animal_menu(animal)
  end
end

#callObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sea_life/cli.rb', line 3

def call
  puts "------------------------------------------------------------"
  puts ""
  puts "      _________             .____    .__  _____"
  puts "     /   _____/ ____ _____  |    |   |__|/ ____\\____"
  puts "     \\_____  \\_/ __ \\\\__  \\ |    |   |  \\   __\\/ __ \\"
  puts "     /        \\  ___/ / __ \\|    |___|  ||  | \\  ___/"
  puts "    /_________/\\____/ _____/ ________\\__||__|  \\____/"
  puts ""
  puts ""
  puts "------------------------------------------------------------"
  puts ""
  puts "Welcome!"

  list_categories
end

#category_menu(animals) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sea_life/cli.rb', line 125

def category_menu(animals)
  puts "Please enter the number of your selection."
  puts "You may also enter BACK or EXIT"

  input = gets.strip

  if input.to_i > 0 && input.to_i <= animals.size
    show_animal(animals[input.to_i - 1])
  elsif input.downcase == "back"
    list_categories
  elsif input.downcase == "exit"
    goodbye
  else
    puts "Invalid input."
    category_menu(animals)
  end
end

#goodbyeObject



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/sea_life/cli.rb', line 143

def goodbye
  puts "------------------------------------------------------------"
  puts ""
  puts "      _________             .____    .__  _____"
  puts "     /   _____/ ____ _____  |    |   |__|/ ____\\____"
  puts "     \\_____  \\_/ __ \\\\__  \\ |    |   |  \\   __\\/ __ \\"
  puts "     /        \\  ___/ / __ \\|    |___|  ||  | \\  ___/"
  puts "    /_________/\\____/ _____/ ________\\__||__|  \\____/"
  puts "                                        See you soon!"
  puts ""
  puts "------------------------------------------------------------"
end

#list_animals(category) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sea_life/cli.rb', line 42

def list_animals(category)
  puts "Loading animals..."
  puts ""

  make_animals_from_category(category) if category.animals.size == 0

  puts "Please select the animal you'd like to learn about:"

  animals = []
  category.animals.each_with_index do |animal, i|
    puts "#{i + 1}. #{animal.name}"
    animals << animal
  end

  puts ""

  category_menu(animals)
end

#list_categoriesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sea_life/cli.rb', line 20

def list_categories
  puts ""
  puts "Please choose a category to learn about:"
  puts ""

  make_categories if SeaLife::Category.all.size == 0
  categories = SeaLife::Category.all

  categories.each_with_index do |category, i|
    puts "#{i + 1}. #{category.name}"
  end

  puts ""
  main_menu(categories)
end


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/sea_life/cli.rb', line 109

def main_menu(categories)
  puts "Please enter the number of a category:"
  puts "You may also enter \"EXIT\"."

  input = gets.strip

  if input.to_i > 0 && input.to_i <= categories.size
    list_animals(categories[input.to_i - 1])
  elsif input.downcase == "exit"
    goodbye
  else
    puts "Invalid input."
    main_menu(categories)
  end
end

#make_animals_from_category(category) ⇒ Object



62
63
64
# File 'lib/sea_life/cli.rb', line 62

def make_animals_from_category(category)
  SeaLife::Scraper.scrape_animals(category)
end

#make_categoriesObject



36
37
38
39
40
# File 'lib/sea_life/cli.rb', line 36

def make_categories
  SeaLife::Scraper.scrape_categories.each do |category|
    SeaLife::Category.new(category)
  end
end

#show_animal(animal) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sea_life/cli.rb', line 66

def show_animal(animal)
  SeaLife::Scraper.scrape_animal_info(animal) unless animal.scientific_name

  puts ""
  puts "--------------------------------------------------------------"
  puts "#{animal.name} (#{animal.scientific_name})"
  puts ""
  puts "Distribution:  #{animal.distribution}"
  puts "Ecosystem/Habitat: #{animal.habitat}"
  puts "Feeding Habits: #{animal.habits}"
  puts "Conservation Status: #{animal.status}"
  puts "Taxonomy: #{animal.taxonomy}"
  puts "--------------------------------------------------------------"
  puts ""
  puts "#{animal.short_desc}"
  puts ""
  puts "Enter \"MORE\" to continue reading about the #{animal.name}."
  puts "You may also enter \"BACK\", \"MENU\", or \"EXIT\"."

  animal_menu(animal)
end