Created
September 28, 2015 15:14
-
-
Save John-Lin/fd821d1e425ddfd41bbb to your computer and use it in GitHub Desktop.
For SOA Serialization homework
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
| if ARGV[1].nil? | |
| print 'Insert the name of your output file (tsv file) ' | |
| outname = $stdin.gets.chomp | |
| else | |
| outname = ARGV[1] | |
| end | |
| # Deserialize | |
| require 'yaml' | |
| survey = YAML.load(File.read(ARGV[0])) | |
| # Create the TSV file | |
| first_hash = survey[0] | |
| keys_array = first_hash.keys | |
| line = '' | |
| keys_array.each { |key| line.concat(key + "\t") } | |
| File.open(outname, 'w') do |file| | |
| file.puts line.chomp("\t") | |
| survey.each do |record| | |
| file << record.map{|k,v| "#{v}"}.join("\t") | |
| file << "\n" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment