Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def tsv_to_yml(input, output)
  2. lines = []
  3. open_file = File.open(input, 'r')
  4. open_file.each { |line| lines.push line }
  5. open_file.close
  6. tags = lines[0].split("\t")
  7.  
  8. write_file = nil
  9. write_file = File.open(output, 'w') unless output.nil?
  10.  
  11. case write_file
  12. when nil then puts '---'
  13. else write_file.write("---\n")
  14. end
  15.  
  16. (1...lines.size).each do |line_number|
  17. values = lines[line_number].split("\t")
  18. (0..5).each do |i|
  19. print_line = ''
  20. case i
  21. when 0 then print_line = '- '
  22. else print_line = ' '
  23. end
  24. print_line = print_line + "#{tags[i]}: #{values[i]}".delete("\n") + "\n"
  25. case write_file
  26. when nil then puts print_line
  27. else write_file.write(print_line)
  28. end
  29. end
  30. end
  31. end
  32.  
  33. input = ARGV[0]
  34. output = ARGV[1]
  35.  
  36. tsv_to_yml(input, output) unless input.nil?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement