Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'yaml'
- def get_head(informations)
- informations[0].keys.join("\t")
- end
- def get_content(informations)
- info = ''
- informations.each do |information|
- info << information.values.join("\t") << "\n"
- end
- info
- end
- def read_yaml(file)
- YAML.load(File.read(file))
- end
- fail ArgumentError, "Usage: YAML_to_TSV input_file (output_file)\n" if \
- ARGV.count == 0 || ARGV.count > 2
- fail ArgumentError, "The file is not exist\n" unless File.exist? ARGV[0].to_s
- input = read_yaml ARGV[0]
- result = get_head(input) << "\n" << get_content(input)
- if ARGV.count != 1
- File.open(ARGV[1], 'w') do |file|
- file.puts result
- end
- else
- puts result
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement