Class: CoronaVirusCLI::Country

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, total, deaths, recovered, active) ⇒ Country

Returns a new instance of Country.



14
15
16
17
18
19
20
21
22
# File 'lib/corona_virus_cli/country.rb', line 14

def initialize(name, total, deaths, recovered, active)
  self.name = name
  self.total = total
  self.deaths = deaths
  self.recovered = recovered
  self.active = active

  self.save
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



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

def active
  @active
end

#deathsObject

Returns the value of attribute deaths.



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

def deaths
  @deaths
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#recoveredObject

Returns the value of attribute recovered.



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

def recovered
  @recovered
end

#totalObject

Returns the value of attribute total.



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

def total
  @total
end

Class Method Details

.allObject



6
7
8
# File 'lib/corona_virus_cli/country.rb', line 6

def self.all
  @@all
end

.find_by_name(name) ⇒ Object



31
32
33
# File 'lib/corona_virus_cli/country.rb', line 31

def self.find_by_name(name)
  self.all.detect {|obj| obj.name == name}
end

.sort_by_deathsObject



24
25
26
27
28
29
# File 'lib/corona_virus_cli/country.rb', line 24

def self.sort_by_deaths

  self.all.sort_by do |country| 
    country.deaths.gsub(',', '').to_i
  end.reverse
end

Instance Method Details

#saveObject



10
11
12
# File 'lib/corona_virus_cli/country.rb', line 10

def save
  @@all << self
end