Thursday, 29 August 2013

ruby read a file and select best results

ruby read a file and select best results

Hi Guys I am new with Ruby and I am trying to pick the best 3 results from
a csv file I read the file ok I have no problem but I can`t pick up the
best results from my file. Many thanks in advance This is what I have so
far to pick the best 3 results from a file
csv file:
Brain 345677
Mary 5
John 23355676
William 432200
Jessica 21
elements = []
file = File.open'ballots.csv', 'r' do |file|
header = false
ballots=[]
results=[]
while line= file.gets
unless header
element = line.split ','
if [:ballots1] > [:ballots2]
results = ballots1
end
else
results= ballots2
end
puts "#{element[3]}:#{element[4]}"
end
header = false
end

No comments:

Post a Comment