Forked from potatosalad/Ruby script to convert CSV to YAML
Created
July 24, 2013 17:11
-
-
Save rcorreia/6072496 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# | |
# Originally written by http://redartisan.com/tags/csv | |
# Added and minor changes by Gavin Laking | |
# | |
# "id","name","mime_type","extensions","icon_url" | |
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif" | |
# "2","image/tiff","image/tiff","|tiff|tif|","/images/icon/blank.png" | |
require 'csv' | |
class String | |
def unquote | |
self.gsub(/^"|"$/, '') | |
end | |
end | |
# first line contains the field names | |
line = gets | |
fields = line.split('","').collect {|f| f.unquote.chomp} | |
CSV::Reader.parse(STDIN) do |row| | |
fixture = "#{row[1].downcase}_#{row[0]}:\n" | |
fields.each_with_index do |field, i| | |
fixture += " #{field}: \"#{row[i]}\"\n" | |
end | |
puts fixture; puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment