SCDBtoYAML 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2012 Blackacre Labs
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # SCDBtoYAML
2
+
3
+ Convert [Supreme Court Data Base](http://scdb.wustl.edu) Comma-Separated Value (CSV) files into [YAML](http://www.yaml.org)
4
+
5
+ ## Usage
6
+
7
+ Install the gem in the usual way:
8
+
9
+ $ gem install SCDBtoYAML
10
+
11
+ The gem will install a script for command line use:
12
+
13
+ $ SCDBtoYAML help
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'SCDBtoYAML/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "SCDBtoYAML"
8
+ gem.version = SCDBtoYAML::VERSION
9
+ gem.authors = ["Kyle Mitchell"]
10
+ gem.email = ["kyle@blackacrelabs.org"]
11
+ gem.description = %q{Convert SCDB CSV files to YAML}
12
+ gem.summary = %q{Convert Supreme Court Database data files in CSV format into human-readable YAML files}
13
+ gem.homepage = "http://www.github.com/BlackacreLabs/scdbtoyaml"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'thor', '~> 0.16.0'
21
+ end
data/bin/SCDBtoYAML ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'SCDBtoYAML'
4
+
5
+ SCDBtoYAML::CLI.start(ARGV)
data/lib/SCDBtoYAML.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "SCDBtoYAML/version"
2
+ require "SCDBtoYAML/cli"
3
+ require "SCDBtoYAML/converter"
4
+
5
+ module SCDBtoYAML
6
+ end
@@ -0,0 +1,14 @@
1
+ require 'thor'
2
+
3
+ module SCDBtoYAML
4
+ class CLI < Thor
5
+ default_task :convert
6
+ desc "convert", "Convert a Supreme Court Database CSV file to YAML"
7
+ option :in, :aliases => '-i', :required => true, :banner => 'input file'
8
+ option :out, :aliases => '-o', :required => true, :banner => 'output'
9
+ def convert()
10
+ hashes = Converter.convert_file(options[:in])
11
+ File.open(options[:out], 'wb') {|f| f.write(hashes.to_yaml) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'csv'
2
+
3
+ module SCDBtoYAML
4
+ class Converter
5
+ # convert a UTF-8 CSV string into yaml
6
+ # applying the SCDB codebook
7
+ def self.convert(text)
8
+ hashes = CSV.parse(
9
+ text,
10
+ :headers => true, # first row is header
11
+ :converters => :all # detect numbers and dates
12
+ ).map{|x| post_process(x.to_hash) }
13
+ end
14
+
15
+ # deal with the encoding of SCDB CSV files
16
+ def self.convert_file(file)
17
+ # There are \xA7 ISO-8859 section symbols
18
+ c = File.open(file, 'r:iso-8859-1').read.encode('utf-8')
19
+ Converter.convert(c)
20
+ end
21
+
22
+ # TODO: apply the codebook
23
+ def self.post_process(hashes)
24
+ hashes
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module SCDBtoYAML
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SCDBtoYAML
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kyle Mitchell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.16.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.16.0
30
+ description: Convert SCDB CSV files to YAML
31
+ email:
32
+ - kyle@blackacrelabs.org
33
+ executables:
34
+ - SCDBtoYAML
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - SCDBtoYAML.gemspec
44
+ - bin/SCDBtoYAML
45
+ - lib/SCDBtoYAML.rb
46
+ - lib/SCDBtoYAML/cli.rb
47
+ - lib/SCDBtoYAML/converter.rb
48
+ - lib/SCDBtoYAML/version.rb
49
+ homepage: http://www.github.com/BlackacreLabs/scdbtoyaml
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Convert Supreme Court Database data files in CSV format into human-readable
73
+ YAML files
74
+ test_files: []