Skip to content
This repository was archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
working dumb conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kemitchell committed Nov 6, 2012
0 parents commit 9b675b4
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
9 changes: 9 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright (c) 2012 Blackacre Labs

MIT License

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SCDBtoYAML

Convert [Supreme Court Data Base](http://scdb.wustl.edu) Comma-Separated Value (CSV) files into [YAML](http://www.yaml.org)

## Usage

Install the gem in the usual way:

$ gem install SCDBtoYAML

The gem will install a script for command line use:

$ SCDBtoYAML help

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
21 changes: 21 additions & 0 deletions SCDBtoYAML.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'SCDBtoYAML/version'

Gem::Specification.new do |gem|
gem.name = "SCDBtoYAML"
gem.version = SCDBtoYAML::VERSION
gem.authors = ["Kyle Mitchell"]
gem.email = ["[email protected]"]
gem.description = %q{Convert SCDB CSV files to YAML}
gem.summary = %q{Convert Supreme Court Database data files in CSV format into human-readable YAML files}
gem.homepage = "http://www.github.com/BlackacreLabs/scdbtoyaml"

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_dependency 'thor', '~> 0.16.0'
end
5 changes: 5 additions & 0 deletions bin/SCDBtoYAML
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'SCDBtoYAML'

SCDBtoYAML::CLI.start(ARGV)
6 changes: 6 additions & 0 deletions lib/SCDBtoYAML.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "SCDBtoYAML/version"
require "SCDBtoYAML/cli"
require "SCDBtoYAML/converter"

module SCDBtoYAML
end
14 changes: 14 additions & 0 deletions lib/SCDBtoYAML/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'thor'

module SCDBtoYAML
class CLI < Thor
default_task :convert
desc "convert", "Convert a Supreme Court Database CSV file to YAML"
option :in, :aliases => '-i', :required => true, :banner => 'input file'
option :out, :aliases => '-o', :required => true, :banner => 'output'
def convert()
hashes = Converter.convert_file(options[:in])
File.open(options[:out], 'wb') {|f| f.write(hashes.to_yaml) }
end
end
end
27 changes: 27 additions & 0 deletions lib/SCDBtoYAML/converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'csv'

module SCDBtoYAML
class Converter
# convert a UTF-8 CSV string into yaml
# applying the SCDB codebook
def self.convert(text)
hashes = CSV.parse(
text,
:headers => true, # first row is header
:converters => :all # detect numbers and dates
).map{|x| post_process(x.to_hash) }
end

# deal with the encoding of SCDB CSV files
def self.convert_file(file)
# There are \xA7 ISO-8859 section symbols
c = File.open(file, 'r:iso-8859-1').read.encode('utf-8')
Converter.convert(c)
end

# TODO: apply the codebook
def self.post_process(hashes)
hashes
end
end
end
3 changes: 3 additions & 0 deletions lib/SCDBtoYAML/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module SCDBtoYAML
VERSION = "0.0.1"
end

0 comments on commit 9b675b4

Please sign in to comment.