Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix to the right plist format

  • Loading branch information...
commit 6a54b9bd281e914fd76b45383967ce4d5413bdc9 1 parent 36c62fe
@naoty authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 copy_csv_to_plist
View
12 copy_csv_to_plist
@@ -8,30 +8,32 @@ module CSV2Plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
-<dict>
+<array>
EOF
PLIST_FOOTER = <<-EOF
-</dict>
+</array>
</plist>
EOF
def self.convert(csv, plist)
File.open(plist, 'wb') do |file|
- file << PLIST_HEADER
+ file.puts(PLIST_HEADER)
CSV.foreach(csv, headers: true) do |row|
+ file.puts('<dict>')
row.each_with_index do |header, field|
file.puts("<key>#{row.headers[field]}</key>")
file.puts("<string>#{row[field]}</string>")
end
+ file.puts('</dict>')
end
- file << PLIST_FOOTER
+ file.puts(PLIST_FOOTER)
end
end
end
if ARGV.length < 2
- puts 'USAGE: csv2plist [filename] [target]'
+ puts 'USAGE: csv2plist [csv] [plist]'
abort
end
Please sign in to comment.
Something went wrong with that request. Please try again.