csv2plist 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in csv2plist.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Denis Hennessy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ csv2plist
2
+ =========
3
+
4
+ # DESCRIPTION
5
+
6
+ Property list files are a great way to store data within your iOS or OS/X
7
+ application - they're well-structured and super-easy to parse. CSV (comma-
8
+ separated variable) files are a great to export data from a spreadsheet
9
+ which is _much_ easier to edit than the raw PLIST files.
10
+
11
+ csv2plist is a utility program that converts files from CSV format into
12
+ property lists. The root level of the property list will be an array and
13
+ each element of the array will be a dictionary, corresponding to the
14
+ equivalent row in the spreadsheet. The keys of the dictionary are the
15
+ column names and the values are the column values.
16
+
17
+ # INSTALLATION
18
+
19
+ csv2plist is a ruby gem. Install it with the following command
20
+
21
+ $ sudo gem install csv2plist
22
+
23
+ If your terminal environment is set up sanely, you should be able to run
24
+ it by simply invoking it at a shell prompt:
25
+
26
+ $ csv2plist -h
27
+ csv2plist converts a .....
28
+
29
+ # USAGE
30
+
31
+ If your CSV file contains a header row, and only contains string values,
32
+ then you can simply do this:
33
+
34
+ $ csv2plist sample.csv
35
+
36
+ This will create a property list file called sample.plist.
37
+
38
+ See `csv2plist -h` for other options.
39
+
40
+ # CONVERSION EXAMPLES
41
+
42
+ ## Basic Strings
43
+
44
+ If `test.csv` contains the following:
45
+
46
+ name,age
47
+ John,23
48
+ Mark,25
49
+
50
+ Converting it with `csv2plist test.csv` will produce a file containing:
51
+
52
+ <?xml version="1.0" encoding="UTF-8"?>
53
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
54
+ <plist version="1.0">
55
+ <array>
56
+ <dict>
57
+ <key>age</key>
58
+ <string>23</string>
59
+ <key>name</key>
60
+ <string>John</string>
61
+ </dict>
62
+ <dict>
63
+ <key>age</key>
64
+ <string>25</string>
65
+ <key>name</key>
66
+ <string>Mark</string>
67
+ </dict>
68
+ </array>
69
+ </plist>
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/csv2plist ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2011-3-19.
4
+ # Copyright (c) 2011. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/csv2plist")
8
+ require "csv2plist/cli"
9
+
10
+ Csv2plist::CLI.execute(STDOUT, ARGV)
data/csv2plist.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "csv2plist/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "csv2plist"
7
+ s.version = Csv2plist::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Denis Hennessy"]
10
+ s.email = ["denis@hennessynet.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Convert a CSV file to a PLIST file.}
13
+ s.description = %q{Takes a comma-separated variable (CSV) file and generates a Property List (PLIST) file from it structured as an array of dictionaries, one for each row.}
14
+ s.bindir = "bin"
15
+
16
+ s.rubyforge_project = "csv2plist"
17
+
18
+ s.add_dependency('fastercsv', '>= 1.5.3')
19
+ s.add_dependency('plist', '>= 3.1.0')
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,46 @@
1
+ require 'optparse'
2
+
3
+ module Csv2plist
4
+ class CLI
5
+ def self.execute(stdout, arguments=[])
6
+
7
+ # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
8
+
9
+ options = {
10
+ :outputfile => nil
11
+ }
12
+ mandatory_options = %w( )
13
+
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = <<-BANNER.gsub(/^ /,'')
16
+ csv2plist converts a comma-separated variable (CSV) file to a property
17
+ list (PLIST) xml file structured as an array of dictionary elements. Each
18
+ dictionary will have a mapping from the column heading to the value on
19
+ the corresponding row.
20
+
21
+ Usage: #{File.basename($0)} [options] <csvfile>
22
+
23
+ Options are:
24
+ BANNER
25
+ opts.separator ""
26
+ opts.on("-o", "--output PATH", String,
27
+ "Specify the output file.",
28
+ "Default: source file, with .plist extension") { |arg| options[:outputfile] = arg }
29
+ opts.on("-h", "--help",
30
+ "Show this help message.") { stdout.puts opts; exit }
31
+ opts.parse!(arguments)
32
+
33
+ if arguments.empty? || mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
34
+ stdout.puts opts;
35
+ exit
36
+ end
37
+ end
38
+
39
+ srcfile = arguments[0]
40
+ outputfile = options[:outputfile] || srcfile.gsub(/.csv/i, ".plist")
41
+ outputfile = outputfile + ".plist" if outputfile == srcfile
42
+
43
+ Csv2plist.convert(srcfile, outputfile)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Csv2plist
2
+ VERSION = "0.0.1"
3
+ end
data/lib/csv2plist.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'fastercsv'
2
+ require 'plist'
3
+
4
+ $:.unshift(File.dirname(__FILE__)) unless
5
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+
8
+ module Csv2plist
9
+ def self.convert(src, dst, opts={})
10
+ rows = FasterCSV.read(src)
11
+ cols = rows[0]
12
+ entries = []
13
+ puts "Columns: #{cols.inspect}"
14
+ (1..rows.length-1).each do |row|
15
+ vals = rows[row]
16
+ dict = {}
17
+ cols.each_with_index do |c,i|
18
+ if vals[i]
19
+ value = vals[i].strip
20
+ dict[c] = value if c && value.length > 0
21
+ end
22
+ end
23
+ entries << dict
24
+ end
25
+ entries.save_plist(dst)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv2plist
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Denis Hennessy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-24 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: fastercsv
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 1
32
+ - 5
33
+ - 3
34
+ version: 1.5.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: plist
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 3
48
+ - 1
49
+ - 0
50
+ version: 3.1.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Takes a comma-separated variable (CSV) file and generates a Property List (PLIST) file from it structured as an array of dictionaries, one for each row.
54
+ email:
55
+ - denis@hennessynet.com
56
+ executables:
57
+ - csv2plist
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/csv2plist
69
+ - csv2plist.gemspec
70
+ - lib/csv2plist.rb
71
+ - lib/csv2plist/cli.rb
72
+ - lib/csv2plist/version.rb
73
+ has_rdoc: true
74
+ homepage: ""
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: csv2plist
103
+ rubygems_version: 1.5.2
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Convert a CSV file to a PLIST file.
107
+ test_files: []
108
+