Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. require 'yaml'
  2. file = File.open(ARGV[0], "r").read
  3. label = []
  4. students = []
  5. file.each_line do |line|
  6. lines =line.split(' ')
  7. student = {}
  8. if label.empty?
  9. label = lines.collect{ |x| x.strip }
  10. else
  11. lines.each_with_index do |item,index|
  12. student[label[index]] = item.strip
  13. end
  14. students.push(student)
  15. end
  16. end
  17. if ARGV[1]
  18. File.open(ARGV[1], "w") do |file|
  19. file.puts students.to_yaml
  20. end
  21. else
  22. pu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement