Class: Covidstats::Country
- Inherits:
-
Object
- Object
- Covidstats::Country
- Defined in:
- lib/covidstats/country.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#active_cases ⇒ Object
Returns the value of attribute active_cases.
-
#continent ⇒ Object
Returns the value of attribute continent.
-
#deaths_per_mil ⇒ Object
Returns the value of attribute deaths_per_mil.
-
#name ⇒ Object
Returns the value of attribute name.
-
#new_cases ⇒ Object
Returns the value of attribute new_cases.
-
#new_deaths ⇒ Object
Returns the value of attribute new_deaths.
-
#population ⇒ Object
Returns the value of attribute population.
-
#serious_critical ⇒ Object
Returns the value of attribute serious_critical.
-
#tests_per_mil ⇒ Object
Returns the value of attribute tests_per_mil.
-
#total_cases ⇒ Object
Returns the value of attribute total_cases.
-
#total_cases_per_mil ⇒ Object
Returns the value of attribute total_cases_per_mil.
-
#total_deaths ⇒ Object
Returns the value of attribute total_deaths.
-
#total_recovered ⇒ Object
Returns the value of attribute total_recovered.
-
#total_tests ⇒ Object
Returns the value of attribute total_tests.
Class Method Summary collapse
Instance Method Summary collapse
- #hash_attr(hash) ⇒ Object
-
#initialize(country_hash) ⇒ Country
constructor
A new instance of Country.
- #save ⇒ Object
Constructor Details
#initialize(country_hash) ⇒ Country
5 6 7 8 |
# File 'lib/covidstats/country.rb', line 5 def initialize(country_hash) hash_attr(country_hash) save end |
Instance Attribute Details
#active_cases ⇒ Object
Returns the value of attribute active_cases.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def active_cases @active_cases end |
#continent ⇒ Object
Returns the value of attribute continent.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def continent @continent end |
#deaths_per_mil ⇒ Object
Returns the value of attribute deaths_per_mil.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def deaths_per_mil @deaths_per_mil end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def name @name end |
#new_cases ⇒ Object
Returns the value of attribute new_cases.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def new_cases @new_cases end |
#new_deaths ⇒ Object
Returns the value of attribute new_deaths.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def new_deaths @new_deaths end |
#population ⇒ Object
Returns the value of attribute population.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def population @population end |
#serious_critical ⇒ Object
Returns the value of attribute serious_critical.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def serious_critical @serious_critical end |
#tests_per_mil ⇒ Object
Returns the value of attribute tests_per_mil.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def tests_per_mil @tests_per_mil end |
#total_cases ⇒ Object
Returns the value of attribute total_cases.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def total_cases @total_cases end |
#total_cases_per_mil ⇒ Object
Returns the value of attribute total_cases_per_mil.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def total_cases_per_mil @total_cases_per_mil end |
#total_deaths ⇒ Object
Returns the value of attribute total_deaths.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def total_deaths @total_deaths end |
#total_recovered ⇒ Object
Returns the value of attribute total_recovered.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def total_recovered @total_recovered end |
#total_tests ⇒ Object
Returns the value of attribute total_tests.
2 3 4 |
# File 'lib/covidstats/country.rb', line 2 def total_tests @total_tests end |
Class Method Details
.all ⇒ Object
41 42 43 |
# File 'lib/covidstats/country.rb', line 41 def self.all @@all end |
.create_from_collection(countries_array) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/covidstats/country.rb', line 33 def self.create_from_collection(countries_array) countries_array.delete_if { |h| h["Country"] == "World"} countries_array.delete_if { |h| h["Country"] == "Total:"} countries_array.each do |country| self.new(country) end end |
Instance Method Details
#hash_attr(hash) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/covidstats/country.rb', line 10 def hash_attr(hash) hash = hash.each do |key, value| hash[key] = value.gsub(",","").gsub("+","") if key != "Continent" && key != "Country" hash[key] = hash[key].to_i end end @total_cases = hash["TotalCases"] @new_cases = hash["NewCases"] @total_deaths = hash["TotalDeaths"] @new_deaths = hash["NewDeaths"] @total_recovered = hash["TotalRecovered"] @active_cases = hash["ActiveCases"] @total_tests = hash["TotalTests"] @population = hash["Population"] @continent = hash["Continent"] @deaths_per_mil = hash["Deaths_1M_pop"] @name = hash["Country"] @serious_critical = hash["Serious_Critical"] @tests_per_mil = hash["Tests_1M_Pop"] @total_cases_per_mil = hash["TotCases_1M_Pop"] end |
#save ⇒ Object
45 46 47 |
# File 'lib/covidstats/country.rb', line 45 def save @@all << self end |