Sha256: a6d9333b5e2df36a8abab77c1894554e91ca8e1e109f7e4444f91831aa028f9c

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby

require 'dbf'
require 'dbf/version'
require 'optparse'

params = ARGV.getopts('h', 's', 'a', 'c', 'r', 'v')

if params['v']
  puts "dbf version: #{DBF::VERSION}"

elsif params['h'] then
  puts "usage: #{File.basename(__FILE__)} [-h|-s|-a|-c|-r] filename"
  puts "  -h = print this message"
  puts "  -v = print the DBF gem version"
  puts "  -s = print summary information"
  puts "  -a = create an ActiveRecord::Schema"
  puts "  -r = create a Sequel migration"
  puts "  -c = create a CSV file"
else

  filename = ARGV.shift
  abort "You must supply a filename on the command line" unless filename

  # create an ActiveRecord::Schema
  if params['a']
    table = DBF::Table.new filename
    puts table.schema(:activerecord)
  end

  # create an Sequel::Migration
  if params['r']
    table = DBF::Table.new filename
    puts table.schema(:sequel)
  end

  if params['s']
    table = DBF::Table.new filename
    puts
    puts "Database: #{filename}"
    puts "Type: (#{table.version}) #{table.version_description}"
    puts "Memo File: #{table.has_memo_file? ? 'true' : 'false'}"
    puts "Records: #{table.record_count}"

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

  if params['c']
    table = DBF::Table.new filename
    table.to_csv
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dbf-3.1.1 bin/dbf
dbf-3.1.0 bin/dbf
dbf-3.0.8 bin/dbf
dbf-3.0.7 bin/dbf
dbf-3.0.5 bin/dbf