Class: CoronaVirusCLI::CLI
- Inherits:
-
Object
- Object
- CoronaVirusCLI::CLI
- Defined in:
- lib/corona_virus_cli/cli.rb
Instance Attribute Summary collapse
-
#virus ⇒ Object
readonly
Returns the value of attribute virus.
Instance Method Summary collapse
- #call ⇒ Object
- #display_active ⇒ Object
- #display_closed ⇒ Object
- #display_country ⇒ Object
- #display_totals ⇒ Object
- #list_countries ⇒ Object
- #list_options ⇒ Object
- #main_loop ⇒ Object
- #option(i) ⇒ Object
Instance Attribute Details
#virus ⇒ Object (readonly)
Returns the value of attribute virus.
2 3 4 |
# File 'lib/corona_virus_cli/cli.rb', line 2 def virus @virus end |
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/corona_virus_cli/cli.rb', line 4 def call puts "*****Loading data from the web...*****" @virus = CoronaVirusCLI::Scraper.get_virus CoronaVirusCLI::Scraper.get_virus_per_country puts "\n_____COVID-19 World Statistics_____\n" self.main_loop puts "\nThank you, and stay safe!" end |
#display_active ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/corona_virus_cli/cli.rb', line 65 def display_active puts '' puts '--------------------------------' puts "World Active Cases: #{self.virus.active}" puts " In Mild Condition: #{self.virus.active_mild}" puts " In Severe Condition: #{self.virus.active_severe}" puts '--------------------------------' end |
#display_closed ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/corona_virus_cli/cli.rb', line 74 def display_closed puts '' puts '--------------------------------' puts "World Closed Cases: #{self.virus.closed}" puts " Recovered: #{self.virus.closed_recovered}" puts " Deaths: #{self.virus.closed_deaths}" puts '--------------------------------' end |
#display_country ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/corona_virus_cli/cli.rb', line 83 def display_country self.list_countries print "\nWhich country would you like to view? " input = gets.strip.to_i if input.between?(1, self.virus.countries.length) country = self.virus.countries[input - 1] puts '' puts '--------------------------------' puts "#{country.name}:" puts " Total Cases: #{country.total}" puts " Total Deaths: #{country.deaths}" puts " Total Recovered: #{country.recovered}" puts " Active Cases: #{country.active}" puts '--------------------------------' print "\nWould you like to view another country?(Y/N) " repeat = gets.strip.downcase self.display_country if repeat == 'y' else puts "\n___Invalid Input___" self.display_country end end |
#display_totals ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/corona_virus_cli/cli.rb', line 56 def display_totals puts '' puts '--------------------------------' puts "Total Cases: #{self.virus.total}" puts "Total Deaths: #{self.virus.total_deaths}" puts "Total Recovered: #{self.virus.total_recovered}" puts '--------------------------------' end |
#list_countries ⇒ Object
108 109 110 111 112 113 |
# File 'lib/corona_virus_cli/cli.rb', line 108 def list_countries puts "" self.virus.countries.each.with_index(1) do |country, i| puts "#{i}. #{country.name}" end end |
#list_options ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/corona_virus_cli/cli.rb', line 35 def puts "" puts "1. World Total Stats" puts "2. World Active Cases Stats" puts "3. World Closed Cases Stats" puts "4. Stats per Country" puts "5. Exit" end |
#main_loop ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/corona_virus_cli/cli.rb', line 15 def main_loop self. print "\nWhat would you like to do? " input = gets.strip.to_i if input.between?(1, 5) if input == 5 return nil else self.option(input) end else puts "\n___Invalid Input___" self.main_loop end print "\nWould you like to check something else?(Y/N) " input = gets.strip.downcase self.main_loop if input == 'y' end |
#option(i) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/corona_virus_cli/cli.rb', line 44 def option(i) if i == 1 self.display_totals elsif i == 2 self.display_active elsif i == 3 self.display_closed elsif i == 4 self.display_country end end |