Permalink
Browse files

Add a script converting csv into plist

  • Loading branch information...
1 parent 2e0e79e commit 4e9054849bba03070e142b5a15c0d6bf9a549da9 @naoty committed Oct 1, 2012
Showing with 39 additions and 0 deletions.
  1. +39 −0 csv2plist
View
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+
+require 'csv'
+
+module CSV2Plist
+
+ PLIST_HEADER = <<-EOF
+<?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>
+ EOF
+
+ PLIST_FOOTER = <<-EOF
+</dict>
+</plist>
+ EOF
+
+ def self.convert(csv, plist)
+ File.open(plist, 'wb') do |file|
+ file << PLIST_HEADER
+ CSV.foreach(csv, headers: true) do |row|
+ row.each_with_index do |header, field|
+ file.puts("<key>#{row.headers[field]}</key>")
+ file.puts("<string>#{row[field]}</string>")
+ end
+ end
+ file << PLIST_FOOTER
+ end
+ end
+end
+
+if ARGV.length < 2
+ puts 'USAGE: csv2plist [filename] [target]'
+ abort
+end
+
+CSV2Plist.convert(ARGV[0], ARGV[1])
+

0 comments on commit 4e90548

Please sign in to comment.