Sat Aug 09 22:00:00 UTC 2008

Using Ruby to get information about a DBF file

Posted in Ruby at 10:00 PM by mohits

In a previous article, I had written about getting started with the DBF gem to convert a DBF file into a CSV file. In this article, I show how to get basic information about a DBF file by using the gem.


1
2
3
4
5
6
7
8
9
10
11
12
13
require 'rubygems'
require 'dbf'

table = DBF::Table.new(ARGV[0])

puts "Information about #{ARGV[0]}\n\n"
puts "Schema in ActiveRecord Format:"
puts table.schema
puts "\nNumber of colums  - #{table.columns.size}"
table.columns.each_with_index {|col, index|
    puts "#{index},#{col.name},#{col.type},#{col.length},#{col.decimal}"
}
puts "\nNumber of records - #{table.record_count}"

Sorry, comments are closed for this article.