Advertisement
Guest User

Untitled

a guest
Nov 15th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.81 KB | None | 0 0
  1. class Country
  2.   def initialize(string)
  3.     @country_string = string
  4.     @country_data= @country_string.split
  5.     @country_code = @country_data[0]
  6.     @country_gold = @country_data[1]
  7.     @country_silver = @country_data[2]
  8.     @country_bronze = @country_data[3]
  9.     @country_pop = @country_data[4]
  10.   end
  11.  
  12.   def to_s
  13.     return @country_string
  14.   end
  15.   end
  16.  
  17. class MedalRankings
  18.   def initialize
  19.     @countries = Array.new
  20.   end
  21.  
  22.   def add_country(country)
  23.     unless country.nil? {@countries << country}; end
  24.   end
  25.  
  26.   def to_s(n)
  27.     for i in 0..n do
  28.       unless n.nil? {@string << @countries[i].to_s}; end
  29.     end
  30.     return @string
  31.   end
  32.  
  33. end
  34.  
  35. medal_rankings = MedalRankings.new
  36. IO.foreach('medals.txt') do |line|
  37.   medal_rankings.add_country(Country.new(line))
  38. end
  39. puts medal_rankings.to_s(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement