class EndangeredSpecies::CLI
This is a CLI
that displays information scraped from www.worldwildlife.org
Attributes
animals[R]
Public Instance Methods
animal_info_handler(num)
click to toggle source
# File lib/endangered_species/cli.rb, line 34 def animal_info_handler(num) EndangeredSpecies::Scraper.select_animal_attributes(@animals[num]) put_animal_info(@animals[num]) prompt_for_more_info(@animals[num]) end
animal_list_handler()
click to toggle source
# File lib/endangered_species/cli.rb, line 27 def animal_list_handler puts "Here are the endangered species:\n\n" list_animals puts "\n#{Rainbow('Which animal would you like more information about?').bright} #{Rainbow("(Enter '1'-'#{animals.length}', or 'exit')").aqua}\n\n" menu end
call()
click to toggle source
# File lib/endangered_species/cli.rb, line 9 def call @animals = EndangeredSpecies::Scraper.endangered_species animal_list_handler end
list_animals()
click to toggle source
# File lib/endangered_species/cli.rb, line 40 def list_animals animals.each.with_index(1) { |animal, index| puts "\t#{Rainbow(index).cyan}. #{animal.name}" } end
more_info(animal)
click to toggle source
# File lib/endangered_species/cli.rb, line 55 def more_info(animal) puts WordWrap.ww("\n\t#{animal.description.join("\n\n\t")}") puts "\n#{Rainbow('Would you like to learn about another animal?').bright} #{Rainbow('(Enter \'list\' or \'exit\')').aqua}" menu end
prompt_for_more_info(animal)
click to toggle source
# File lib/endangered_species/cli.rb, line 50 def prompt_for_more_info(animal) puts "\n#{Rainbow('Would you like more information, or to see the list again?').bright} #{Rainbow("(Enter 'more' or 'list')").aqua}" gets.chomp.casecmp('more').zero? ? more_info(animal) : animal_list_handler end
put_animal_info(animal)
click to toggle source
# File lib/endangered_species/cli.rb, line 44 def put_animal_info(animal) animal.attribute_names.each do |attribute| puts "\t#{Rainbow(attribute).cyan}: #{animal.send(attribute)}" unless attribute.casecmp('description').zero? || attribute.casecmp('url').zero? end end