Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:naoty/bin

  • Loading branch information...
commit 29137e863ea77e2de15a3284cd45496cc6f00d91 2 parents f7e5ecb + 6a54b9b
@naoty authored
Showing with 41 additions and 0 deletions.
  1. +41 −0 copy_csv_to_plist
View
41 copy_csv_to_plist
@@ -0,0 +1,41 @@
+#!/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">
+<array>
+ EOF
+
+ PLIST_FOOTER = <<-EOF
+</array>
+</plist>
+ EOF
+
+ def self.convert(csv, plist)
+ File.open(plist, 'wb') do |file|
+ 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.puts(PLIST_FOOTER)
+ end
+ end
+end
+
+if ARGV.length < 2
+ puts 'USAGE: csv2plist [csv] [plist]'
+ abort
+end
+
+CSV2Plist.convert(ARGV[0], ARGV[1])
+
Please sign in to comment.
Something went wrong with that request. Please try again.