Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. # appends each waldo find to csv file
  2. def save_scores(time_data)
  3. info = File.open("/Users/Wipf/Code/projects/waldo/views/data.erb", "a") # a to append
  4. info.print "\n"
  5. info.print time_data + " Seconds"
  6. info.close
  7. end
  8.  
  9.  
  10. # Takes all scores and using regular expression takes out the numbers from each line,
  11. # turns that number to a float and sorts.
  12. def getHighestScores
  13.  
  14. timesArray = []
  15. File.open("/Users/Wipf/Code/projects/waldo/views/data.erb", "r") do |data|
  16.  
  17. data.each_line do |time|
  18. time = time[/\d+\S\d/].to_f # regular expressions. Rebular.com
  19. timesArray.push(time)
  20. end
  21. end
  22.  
  23. timesArray = timesArray.sort
  24. timesArray = timesArray[0..9]
  25.  
  26. records = beautifyHighScores(timesArray)
  27. session["highScores"] = records
  28. end
  29.  
  30. # Takes the array of top 10 scores and adds "Seconds!" and new line character
  31. # to each score for display purposes
  32. def beautifyHighScores(data)
  33.  
  34. timesString = ''
  35. data.each do |score|
  36. timesString += "#{score} Seconds <br>"
  37. end
  38.  
  39. return timesString
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement