Skip to content

Commit

Permalink
add badges to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
infused committed Mar 23, 2013
1 parent 0fd71d2 commit 6d9ae97
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,16 @@
# DBF [![Build Status](https://secure.travis-ci.org/infused/dbf.png)](http://travis-ci.org/infused/dbf) # DBF
[![Build Status](https://secure.travis-ci.org/infused/dbf.png)](http://travis-ci.org/infused/dbf)
[![Gem Version](https://badge.fury.io/rb/dbf.png)](http://badge.fury.io/rb/dbf)
[![Code Climate](https://codeclimate.com/github/infused/dbf.png)](https://codeclimate.com/github/infused/dbf)
[![Dependency Status](https://gemnasium.com/infused/dbf.png)](https://gemnasium.com/infused/dbf)


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


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


## Compatibility ## Compatibility
Expand All @@ -19,9 +23,9 @@ DBF is tested to work with the following versions of ruby:
* Rubinius (1.8 mode) * Rubinius (1.8 mode)


## Installation ## Installation

gem install dbf gem install dbf

## Basic Usage ## Basic Usage


Open a DBF file: Open a DBF file:
Expand All @@ -35,11 +39,11 @@ Enumerate all records
puts record.name puts record.name
puts record.email puts record.email
end end

Find a single record Find a single record


widget = widgets.find(6) widget = widgets.find(6)

Note that find() will return nil if the requested record has been deleted Note that find() will return nil if the requested record has been deleted
and not yet pruned from the database. and not yet pruned from the database.


Expand All @@ -49,43 +53,43 @@ ways
widget["SlotNumber"] # original field name in dbf file widget["SlotNumber"] # original field name in dbf file
widget['slot_number'] # underscored field name string widget['slot_number'] # underscored field name string
widget[:slot_number] # underscored field name symbol widget[:slot_number] # underscored field name symbol

Get a hash of all attributes. The keys are the original column names. Get a hash of all attributes. The keys are the original column names.


widgets.attributes widgets.attributes
=> {"Name" => "Thing1", "SlotNumber" => 1} => {"Name" => "Thing1", "SlotNumber" => 1}

Search for records using a simple hash format. Multiple search criteria are Search for records using a simple hash format. Multiple search criteria are
ANDed. Use the block form if the resulting recordset could be large, otherwise ANDed. Use the block form if the resulting recordset could be large, otherwise
all records will be loaded into memory. all records will be loaded into memory.

# find all records with slot_number equal to s42 # find all records with slot_number equal to s42
widgets.find(:all, :slot_number => 's42') do |widget| widgets.find(:all, :slot_number => 's42') do |widget|
# the record will be nil if deleted, but not yet pruned from the database # the record will be nil if deleted, but not yet pruned from the database
if widget if widget
puts widget.serial_number puts widget.serial_number
end end
end end

# find the first record with slot_number equal to s42 # find the first record with slot_number equal to s42
widgets.find :first, :slot_number => 's42' widgets.find :first, :slot_number => 's42'

# find record number 10 # find record number 10
widgets.find(10) widgets.find(10)

## Migrating to ActiveRecord ## Migrating to ActiveRecord


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


require 'dbf' require 'dbf'


class Book < ActiveRecord::Base; end class Book < ActiveRecord::Base; end

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

Book.reset_column_information Book.reset_column_information
table.each do |record| table.each do |record|
Book.create(:title => record.title, :author => record.author) Book.create(:title => record.title, :author => record.author)
Expand All @@ -96,7 +100,7 @@ An example of migrating a DBF book table to ActiveRecord using a migration:
drop_table :books drop_table :books
end end
end end

## Command-line utility ## Command-line utility


A small command-line utility called dbf is installed along with the gem. A small command-line utility called dbf is installed along with the gem.
Expand All @@ -107,15 +111,15 @@ A small command-line utility called dbf is installed along with the gem.
-s = print summary information -s = print summary information
-a = create an ActiveRecord::Schema -a = create an ActiveRecord::Schema
-c = create a csv file -c = create a csv file

Create an executable ActiveRecord schema: Create an executable ActiveRecord schema:

dbf -a books.dbf > books_schema.rb dbf -a books.dbf > books_schema.rb

Dump all records to a CSV file: Dump all records to a CSV file:


dbf -c books.dbf > books.csv dbf -c books.dbf > books.csv

## dBase version support ## dBase version support


The basic dBase data types are generally supported well. Support for the The basic dBase data types are generally supported well. Support for the
Expand Down

0 comments on commit 6d9ae97

Please sign in to comment.