class Covidstats::Country
Attributes
active_cases[RW]
continent[RW]
deaths_per_mil[RW]
name[RW]
new_cases[RW]
new_deaths[RW]
population[RW]
serious_critical[RW]
tests_per_mil[RW]
total_cases[RW]
total_cases_per_mil[RW]
total_deaths[RW]
total_recovered[RW]
total_tests[RW]
Public Class Methods
all()
click to toggle source
# File lib/covidstats/country.rb, line 41 def self.all @@all end
create_from_collection(countries_array)
click to toggle source
# 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
new(country_hash)
click to toggle source
# File lib/covidstats/country.rb, line 5 def initialize(country_hash) hash_attr(country_hash) save end
Public Instance Methods
hash_attr(hash)
click to toggle source
# 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()
click to toggle source
# File lib/covidstats/country.rb, line 45 def save @@all << self end