Class: CountriesOfTheWorld::Country
- Inherits:
-
Object
- Object
- CountriesOfTheWorld::Country
- Defined in:
- lib/countries_of_the_world/country.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#gdp ⇒ Object
Returns the value of attribute gdp.
-
#gdp_growth ⇒ Object
Returns the value of attribute gdp_growth.
-
#income_level ⇒ Object
Returns the value of attribute income_level.
-
#inflation ⇒ Object
Returns the value of attribute inflation.
-
#name ⇒ Object
Returns the value of attribute name.
-
#population ⇒ Object
Returns the value of attribute population.
-
#region ⇒ Object
Returns the value of attribute region.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
-
.list_countries(n) ⇒ Object
print n-items per row.
Instance Method Summary collapse
- #add_info(hash_info) ⇒ Object
-
#initialize(name, url) ⇒ Country
constructor
initialize with name & url, other info are added only when called.
- #list_detail ⇒ Object
Constructor Details
#initialize(name, url) ⇒ Country
initialize with name & url, other info are added only when called
5 6 7 8 9 10 |
# File 'lib/countries_of_the_world/country.rb', line 5 def initialize(name, url) # initialize with name & url, other info are added only when called @name = name @url = url #self.add_info @@all << self end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def description @description end |
#gdp ⇒ Object
Returns the value of attribute gdp.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def gdp @gdp end |
#gdp_growth ⇒ Object
Returns the value of attribute gdp_growth.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def gdp_growth @gdp_growth end |
#income_level ⇒ Object
Returns the value of attribute income_level.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def income_level @income_level end |
#inflation ⇒ Object
Returns the value of attribute inflation.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def inflation @inflation end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def name @name end |
#population ⇒ Object
Returns the value of attribute population.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def population @population end |
#region ⇒ Object
Returns the value of attribute region.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def region @region end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/countries_of_the_world/country.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/countries_of_the_world/country.rb', line 12 def self.all @@all end |
.list_countries(n) ⇒ Object
print n-items per row
20 21 22 23 24 25 26 27 28 |
# File 'lib/countries_of_the_world/country.rb', line 20 def self.list_countries (n) #print n-items per row max_num = @@all.max_by{ |c| c.name.length}.name.length #find the country name with longest name @@all.each.with_index(1) do |c, i| print "#{i.to_s.ljust(5)}".bold.light_blue.on_cyan print "#{c.name.ljust(max_num)}".on_cyan print "\n" if i%n == 0 || i == @@all.size #print \n every nth row end end |
Instance Method Details
#add_info(hash_info) ⇒ Object
16 17 18 |
# File 'lib/countries_of_the_world/country.rb', line 16 def add_info (hash_info) hash_info.each{|k, v| self.send(("#{k}="), v)} end |
#list_detail ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/countries_of_the_world/country.rb', line 30 def list_detail puts "\n" puts "Name: ".bold.magenta+"#{@name}".bold puts "********************************************************".colorize(:red) puts "Population: ".bold.light_blue+"#{@population}" puts "GDP: ".bold.light_blue+"#{@gdp}" puts "GDP Growth: ".bold.light_blue+"#{@gdp_growth}" puts "Inflation: ".bold.light_blue+"#{@inflation}" puts "Region: ".bold.light_blue+"#{@region}" puts "Income_level: ".bold.light_blue+"#{@income_level}" puts "Overview: ".bold.light_blue+"#{@description}" puts "URL: ".bold.light_blue+"#{@url}".bold.light_blue puts "********************************************************".colorize(:red) puts "" end |