Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement