Skip to content

Ruby ADT is a simple library to allow reading of Advantage Database Server ADT (Advantage Database Table) files.

License

Notifications You must be signed in to change notification settings

ak/adt_connector

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTICE

This is an early version and I don't expect it to work in all cases.

Currently, the biggest item that I am working on is getting dates extracted correctly.

If you have suggestions or an .adt file that has issues being read then let me know and I might be able to work on it.

Ruby-ADT

Ruby ADT is a small fast library for reading Advantage Database Server database files (.ADT)

Installation

gem install ruby-adt

Basic Usage

Load an ADT file:

require 'rubygems'
require 'adt'

table = ADT::Table.new("test.adt")

Enumerate all records

table.each do |record|
  puts record.name
  puts record.email
end

Load a single record using record or find

table.record(6)
table.find(6)

Attributes can also be accessed through the attributes hash in original or underscored form or as an accessor method using the underscored name.

table.record(4).attributes["PhoneBook"]
table.record(4).attributes["phone_book"]
table.record(4).phone_book

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

# find all records with first_name equal to Keith
table.find(:all, :first_name => 'Keith') do |record|
  puts record.last_name
end

# find all records with first_name equal to Keith and last_name equal
# to Morrison
table.find(:all, :first_name => 'Keith', :last_name => 'Morrison') do |record|
  puts record.last_name
end

# find the first record with first_name equal to Keith
table.find :first, :first_name => 'Keith'

# find record number 10
table.find(10)

Migrating to ActiveRecord

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

require 'adt'

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

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

  def self.down
    drop_table :books
  end
end

Limitations and known bugs

  • ADT is read-only
  • External index files are not used

Acknowledgements

About

Ruby ADT is a simple library to allow reading of Advantage Database Server ADT (Advantage Database Table) files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%