Class: CommandLineInterface
- Inherits:
-
Object
- Object
- CommandLineInterface
- Defined in:
- lib/marvel_best_superheroes/cli.rb
Constant Summary collapse
- BASEPATH =
"https://comicvine.gamespot.com"
Instance Method Summary collapse
-
#all_superheroes_names ⇒ Object
this method is called when program evokes individual superhero.
-
#all_superheroes_sites ⇒ Object
collect each hero website from AllSuperheroes.
-
#create_superhero(site) ⇒ Object
create a superhero base on user input.
- #display ⇒ Object
-
#display_superhero ⇒ Object
Print out each Superhero’s informations in desired format.
- #get_badge ⇒ Object
- #get_other_input ⇒ Object
- #get_superhero_site ⇒ Object
- #list_all_superheroes(heroes) ⇒ Object
Instance Method Details
#all_superheroes_names ⇒ Object
this method is called when program evokes individual superhero
98 99 100 |
# File 'lib/marvel_best_superheroes/cli.rb', line 98 def all_superheroes_names AllSuperheroes.all.map { |e| "#{e.name}".split(". ")[1]} end |
#all_superheroes_sites ⇒ Object
collect each hero website from AllSuperheroes
93 94 95 |
# File 'lib/marvel_best_superheroes/cli.rb', line 93 def all_superheroes_sites AllSuperheroes.all.map { |e| "#{BASEPATH}#{e.url}"} end |
#create_superhero(site) ⇒ Object
create a superhero base on user input
103 104 105 |
# File 'lib/marvel_best_superheroes/cli.rb', line 103 def create_superhero(site) Superheroes.get_superhero_infos(site) end |
#display ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/marvel_best_superheroes/cli.rb', line 11 def display AllSuperheroes.create_all_superheroes puts "\nHere shows TOP 100 MARVEL SUPERHEROES of all time: ".colorize(:blue) puts "....................................................\n" puts "\nWhat BADGE you are interested in:\n".colorize(:blue) puts "1. OP - TOP 10 MOST BADASS SUPERHEROES".colorize(:blue) puts "2. LEGENDARY - SUPERHEROES RANKED 11-25".colorize(:blue) puts "3. SUPER-DUPER - SUPERHEROES RANKED 26-50".colorize(:blue) puts "4. INCREDIBLE - SUPERHEROES RANKED 51-100".colorize(:blue) get_badge get_superhero_site display_superhero get_other_input end |
#display_superhero ⇒ Object
Print out each Superhero’s informations in desired format
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/marvel_best_superheroes/cli.rb', line 108 def display_superhero Superheroes.all.each do |hero| puts "\n#{hero.name.upcase}".colorize(:blue) puts "" puts " <> Biography:".colorize(:blue) puts "" puts "#{hero.biography}" puts "" puts " <> General Information:".colorize(:blue) puts "\n - Super name:".colorize(:blue) + " #{hero.supername}" puts "\n - Real name:".colorize(:blue) + " #{hero.realname}" puts "\n - Aliases:".colorize(:blue) + " #{hero.aliases}" puts "\n - Gender:".colorize(:blue) + " #{hero.gender}" puts "\n - Character Type:".colorize(:blue) + " #{hero.charactertype}" puts "\n - Birthday:".colorize(:blue) + " #{hero.birthday}" puts "\n - Powers:".colorize(:blue) +" #{hero.powers}" end end |
#get_badge ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/marvel_best_superheroes/cli.rb', line 49 def get_badge puts "\nPlease type in the Badge number to access: " input = gets.strip case input when "1" puts "\n Here comes TOP 10 MOST BADASS/OP SUPERHEROES \n".colorize(:blue) list_all_superheroes(AllSuperheroes.all[0..9]) when "2" puts "\n Here comes the Legendary Superheroes \n".colorize(:blue) list_all_superheroes(AllSuperheroes.all[10..24]) when "3" puts "\n Here comes the Super-duper Superheroes \n".colorize(:blue) list_all_superheroes(AllSuperheroes.all[25..49]) when "4" puts "\n Here comes the Incredible Superheroes \n".colorize(:blue) list_all_superheroes(AllSuperheroes.all[50..100]) else puts "Invalid input" get_badge end end |
#get_other_input ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/marvel_best_superheroes/cli.rb', line 31 def get_other_input puts "Do you want to learn more about other Superheroes?" puts "Type 'Y/Yes' or type 'Exit/No' to end the program" input = gets.strip if input.upcase == "Y" or input.upcase == "YES" get_badge get_superhero_site display_superhero get_other_input elsif input.upcase == "EXIT" || input.upcase == "N" || input.upcase == "NO" puts "\n___May the FORCE be with you!!!___\n".colorize(:blue) else puts "\n Invalid input" get_other_input end end |
#get_superhero_site ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/marvel_best_superheroes/cli.rb', line 71 def get_superhero_site puts "\nWhich superhero do you want to learn more about? " puts "Please type in superhero number:" input = gets.strip.to_i-1 if input >= 0 && input < all_superheroes_sites.size puts "\nPlease wait while we evoke #{all_superheroes_names[input]}...\n" Superheroes.get_superhero_infos(all_superheroes_sites[input]) else puts "Invalid input" puts "Please enter number in above selection" get_superhero_site end end |
#list_all_superheroes(heroes) ⇒ Object
86 87 88 89 90 |
# File 'lib/marvel_best_superheroes/cli.rb', line 86 def list_all_superheroes(heroes) heroes.each do |hero| puts "#{hero.name}" end end |