Skip to content

Commit

Permalink
Fixed conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytse Sijbrandij committed Nov 24, 2009
2 parents 7a51120 + 19f9584 commit d581e36
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 315 deletions.
12 changes: 12 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
== 1.0.9

* Fix incorrect integer column values (only affecting some dbf files)
* Add CSV export

== 1.0.8

* Truncate column names on NULL
* Fix schema dump for date and datetime columns
* Replace internal helpers with ActiveSupport
* Always underscore attribute names

== 1.0.7

* Remove support for original column names. All columns names are now downcased/underscored.
Expand Down
31 changes: 0 additions & 31 deletions Manifest.txt

This file was deleted.

111 changes: 111 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# DBF

DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files

* Project page: <http://github.com/infused/dbf>
* API Documentation: <http://rdoc.info/projects/infused/dbf>
* Report bugs: <http://github.com/infused/dbf/issues>
* Questions: Email <mailto:keithm@infused.org> and put DBF somewhere in the subject line

## Features

* No external dependencies
* Fields are type cast to the appropriate Ruby types
* Ability to dump the database schema in the portable ActiveRecord::Schema format

## Installation

gem install dbf

## Basic Usage

require 'rubygems'
require 'dbf'

table = DBF::Table.new("widgets.dbf")

# Tables are enumerable
widget_ids = table.map { |row| row.id }
abc_names = table.select { |row| row.name =~ /^[a-cA-C]/ }
sorted = table.sort_by { |row| row.name }

# Print the 'name' field from record number 4
puts table.record(4).name

# Attributes can also be accessed using the column name as a Hash key
puts table.record(4).attributes["name"]

# Print the 'name' and 'address' fields from each record
table.records.each do |record|
puts record.name
puts record.email
end

# Find records
table.find :all, :first_name => 'Keith'
table.find :all, :first_name => 'Keith', :last_name => 'Morrison'
table.find :first, :first_name => 'Keith'
table.find(10)

## Migrating to ActiveRecord

An example of migrating a DBF book table to ActiveRecord using a migration:

require 'dbf'

class CreateBooks < ActiveRecord::Migration
def self.up
table = DBF::Table.new('db/dbf/books.dbf')
eval(table.schema)

table.records.each do |record|
Book.create(record.attributes)
end
end

def self.down
drop_table :books
end
end

## Command-line utility

A small command-line utility called dbf is installed along with the gem.

$ dbf -h
usage: dbf [-h|-s|-a] filename
-h = print this message
-s = print summary information
-a = create an ActiveRecord::Schema

## Limitations and known bugs

* DBF is read-only
* Index files are not used

## License

(The MIT Licence)

Copyright (c) 2006-2009 Keith Morrison <mailto:keithm@infused.org>, <http://www.infused.org>

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.
115 changes: 0 additions & 115 deletions README.txt

This file was deleted.

42 changes: 21 additions & 21 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
require 'hoe'
require 'spec/rake/spectask'
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
$: << File.join(PROJECT_ROOT, 'lib')

PKG_NAME = "dbf"
PKG_VERSION = "1.0.7"
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
require 'rubygems'
require 'jeweler'
require 'spec/rake/spectask'
require 'metric_fu'

Hoe.new PKG_NAME, PKG_VERSION do |p|
p.rubyforge_name = PKG_NAME
p.author = "Keith Morrison"
p.email = "keithm@infused.org"
p.summary = "A small fast library for reading dBase, xBase, Clipper and FoxPro database files."
p.description = p.paragraphs_of("README.txt", 1..3).join("\n\n")
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
p.url = "http://github.com/infused/dm-dbf/tree/master"
p.need_tar = true
p.need_zip = true
p.extra_deps << ['activesupport', '>= 2.1.0']
Jeweler::Tasks.new do |s|
s.name = 'dbf'
s.version = '1.0.9'
s.description = 'A small fast library for reading dBase, xBase, Clipper and FoxPro database files.'
s.summary = 'Read xBase files'
s.platform = Gem::Platform::RUBY
s.authors = ['Keith Morrison']
s.email = 'keithm@infused.org'
s.add_dependency('activesupport', ['>= 2.1.0'])
s.add_dependency('fastercsv', ['>= 1.4.0'])
s.homepage = 'http://github.com/infused/dbf'
s.rubyforge_project = 'dbf'
end

Jeweler::GemcutterTasks.new
Jeweler::RubyforgeTasks.new

task :default => :spec

desc "Run specs"
Expand All @@ -30,8 +35,3 @@ Spec::Rake::SpecTask.new :specdoc do |t|
t.spec_opts = ["-f specdoc"]
t.spec_files = FileList['spec/**/*spec.rb']
end

desc "Generate gemspec"
task :gemspec do |t|
`rake debug_gem > dbf.gemspec`
end
5 changes: 5 additions & 0 deletions VERSION.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
:major: 1
:minor: 0
:patch: 10

14 changes: 7 additions & 7 deletions bin/dbf
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ else

# create an ActiveRecord::Schema
if $a
reader = DBF::Table.new filename
puts reader.schema
table = DBF::Table.new filename
puts table.schema
end

if $s
reader = DBF::Table.new filename
table = DBF::Table.new filename
puts
puts "Database: #{filename}"
puts "Type: (#{reader.version}) #{reader.version_description}"
puts "Memo Type: #{reader.memo_file_format}" if reader.has_memo_file?
puts "Records: #{reader.record_count}"
puts "Type: (#{table.version}) #{table.version_description}"
puts "Memo Type: #{table.memo_file_format}" if table.has_memo_file?
puts "Records: #{table.record_count}"

puts "\nFields:"
puts "Name Type Length Decimal"
puts "-" * 78
reader.columns.each do |f|
table.columns.each do |f|
puts "%-16s %-10s %-10s %-10s" % [f.name, f.type, f.length, f.decimal]
end
end
Expand Down
Loading

0 comments on commit d581e36

Please sign in to comment.