Created
September 24, 2017 15:36
-
-
Save ismaelnoble/50b8b7efb598606bbef52b43ec12ddd7 to your computer and use it in GitHub Desktop.
tsv to yaml converter v1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tsv_to_yml(input, output) | |
| lines = [] | |
| open_file = File.open(input, 'r') | |
| open_file.each { |line| lines.push line } | |
| open_file.close | |
| tags = lines[0].split("\t") | |
| write_file = nil | |
| write_file = File.open(output, 'w') unless output.nil? | |
| case write_file | |
| when nil then puts '---' | |
| else write_file.write("---\n") | |
| end | |
| (1...lines.size).each do |line_number| | |
| values = lines[line_number].split("\t") | |
| (0..5).each do |i| | |
| print_line = '' | |
| case i | |
| when 0 then print_line = '- ' | |
| else print_line = ' ' | |
| end | |
| print_line = print_line + "#{tags[i]}: #{values[i]}".delete("\n") + "\n" | |
| case write_file | |
| when nil then puts print_line | |
| else write_file.write(print_line) | |
| end | |
| end | |
| end | |
| end | |
| input = ARGV[0] | |
| output = ARGV[1] | |
| tsv_to_yml(input, output) unless input.nil? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment