Class: Covidstats::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/covidstats/country.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_casesObject

Returns the value of attribute active_cases.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def active_cases
  @active_cases
end

#continentObject

Returns the value of attribute continent.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def continent
  @continent
end

#deaths_per_milObject

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

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def name
  @name
end

#new_casesObject

Returns the value of attribute new_cases.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def new_cases
  @new_cases
end

#new_deathsObject

Returns the value of attribute new_deaths.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def new_deaths
  @new_deaths
end

#populationObject

Returns the value of attribute population.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def population
  @population
end

#serious_criticalObject

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_milObject

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_casesObject

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_milObject

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_deathsObject

Returns the value of attribute total_deaths.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def total_deaths
  @total_deaths
end

#total_recoveredObject

Returns the value of attribute total_recovered.



2
3
4
# File 'lib/covidstats/country.rb', line 2

def total_recovered
  @total_recovered
end

#total_testsObject

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

.allObject



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

#saveObject



45
46
47
# File 'lib/covidstats/country.rb', line 45

def save
  @@all << self
end