dbf 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +15 -0
- data/{README.txt → README.markdown} +54 -54
- data/Rakefile +20 -23
- data/VERSION.yml +5 -0
- data/dbf.gemspec +62 -14
- data/lib/dbf/table.rb +2 -7
- metadata +22 -24
- data/Manifest.txt +0 -31
data/.autotest
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Autotest.add_hook :initialize do |autotest|
|
2
|
+
autotest.clear_mappings
|
3
|
+
|
4
|
+
autotest.add_mapping(%r%^lib/dbf/(.*)\.rb$%) do |filename, m|
|
5
|
+
autotest.files_matching %r!spec/(unit|integration)/#{m[1]}_spec.rb!
|
6
|
+
end
|
7
|
+
|
8
|
+
autotest.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) do |filename, m|
|
9
|
+
filename
|
10
|
+
end
|
11
|
+
|
12
|
+
%w{.svn .hg .git .dbf .dbt .fpt .txt bin Rakefile .gemspec .autotest}.each do |exception|
|
13
|
+
autotest.add_exception(exception)
|
14
|
+
end
|
15
|
+
end
|
@@ -1,93 +1,93 @@
|
|
1
|
-
|
1
|
+
# DBF
|
2
2
|
|
3
3
|
DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files
|
4
4
|
|
5
|
-
Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org
|
5
|
+
Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org>, <www.infused.org>
|
6
6
|
|
7
|
-
* Official project page: http://rubyforge.org/projects/dbf
|
8
|
-
* API Documentation: http://dbf.rubyforge.org/docs
|
9
|
-
* To report bugs: http://www.rubyforge.org/tracker/?group_id=2009
|
7
|
+
* Official project page: <http://rubyforge.org/projects/dbf>
|
8
|
+
* API Documentation: <http://dbf.rubyforge.org/docs>
|
9
|
+
* To report bugs: <http://www.rubyforge.org/tracker/?group_id=2009>
|
10
10
|
* Questions: Email keithm@infused.org and put DBF somewhere in the subject
|
11
11
|
line
|
12
12
|
|
13
|
-
|
13
|
+
## Features
|
14
14
|
|
15
15
|
* No external dependencies
|
16
16
|
* Fields are type cast to the appropriate Ruby types
|
17
17
|
* Ability to dump the database schema in the portable ActiveRecord::Schema
|
18
18
|
format
|
19
19
|
|
20
|
-
|
20
|
+
## Installation
|
21
21
|
|
22
|
-
|
22
|
+
gem install dbf
|
23
23
|
|
24
|
-
|
24
|
+
## Basic Usage
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
require 'rubygems'
|
27
|
+
require 'dbf'
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
# Tables are enumerable
|
32
|
-
widget_ids = table.map { |row| row.id }
|
33
|
-
abc_names = table.select { |row| row.name =~ /^[a-cA-C] }
|
34
|
-
sorted = table.sort_by { |row| row.name }
|
35
|
-
|
36
|
-
# Print the 'name' field from record number 4
|
37
|
-
puts table.record(4).name
|
29
|
+
table = DBF::Table.new("widgets.dbf")
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
# Tables are enumerable
|
32
|
+
widget_ids = table.map { |row| row.id }
|
33
|
+
abc_names = table.select { |row| row.name =~ /^[a-cA-C] }
|
34
|
+
sorted = table.sort_by { |row| row.name }
|
35
|
+
|
36
|
+
# Print the 'name' field from record number 4
|
37
|
+
puts table.record(4).name
|
38
|
+
|
39
|
+
# Attributes can also be accessed using the column name as a Hash key
|
40
|
+
puts table.record(4).attributes["name"]
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
# Print the 'name' and 'address' fields from each record
|
43
|
+
table.records.each do |record|
|
44
|
+
puts record.name
|
45
|
+
puts record.email
|
46
|
+
end
|
47
|
+
|
48
|
+
# Find records
|
49
|
+
table.find :all, :first_name => 'Keith'
|
50
|
+
table.find :all, :first_name => 'Keith', :last_name => 'Morrison'
|
51
|
+
table.find :first, :first_name => 'Keith'
|
52
|
+
table.find(10)
|
53
53
|
|
54
|
-
|
54
|
+
## Migrating to ActiveRecord
|
55
55
|
|
56
56
|
An example of migrating a DBF book table to ActiveRecord using a migration:
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
require 'dbf'
|
59
|
+
|
60
|
+
class CreateBooks < ActiveRecord::Migration
|
61
|
+
def self.up
|
62
|
+
table = DBF::Table.new('db/dbf/books.dbf')
|
63
|
+
eval(table.schema)
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
table.records.each do |record|
|
66
|
+
Book.create(record.attributes)
|
67
|
+
end
|
67
68
|
end
|
68
|
-
end
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
def self.down
|
71
|
+
drop_table :books
|
72
|
+
end
|
72
73
|
end
|
73
|
-
end
|
74
74
|
|
75
|
-
|
75
|
+
## Command-line utility
|
76
76
|
|
77
77
|
A small command-line utility called dbf is installed along with the gem.
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
$ dbf -h
|
80
|
+
usage: dbf [-h|-s|-a] filename
|
81
|
+
-h = print this message
|
82
|
+
-s = print summary information
|
83
|
+
-a = create an ActiveRecord::Schema
|
84
84
|
|
85
|
-
|
85
|
+
## Limitations and known bugs
|
86
86
|
|
87
87
|
* DBF is read-only
|
88
88
|
* Index files are not used
|
89
89
|
|
90
|
-
|
90
|
+
## License
|
91
91
|
|
92
92
|
(The MIT Licence)
|
93
93
|
|
data/Rakefile
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$: << File.join(PROJECT_ROOT, 'lib')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'rubygems'
|
5
|
+
require 'jeweler'
|
6
|
+
require 'spec/rake/spectask'
|
7
7
|
|
8
|
-
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.extra_deps << ['fastercsv', '>= 1.4.0']
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = 'dbf'
|
10
|
+
s.version = '1.0.9'
|
11
|
+
s.description = 'A small fast library for reading dBase, xBase, Clipper and FoxPro database files.'
|
12
|
+
s.summary = 'Read xBase files'
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.authors = ['Keith Morrison']
|
15
|
+
s.email = 'keithm@infused.org'
|
16
|
+
s.add_dependency('activesupport', ['>= 2.1.0'])
|
17
|
+
s.add_dependency('fastercsv', ['>= 1.4.0'])
|
18
|
+
s.homepage = 'http://github.com/infused/dbf'
|
19
|
+
s.rubyforge_project = 'dbf'
|
21
20
|
end
|
22
21
|
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
Jeweler::RubyforgeTasks.new
|
24
|
+
|
23
25
|
task :default => :spec
|
24
26
|
|
25
27
|
desc "Run specs"
|
@@ -32,8 +34,3 @@ Spec::Rake::SpecTask.new :specdoc do |t|
|
|
32
34
|
t.spec_opts = ["-f specdoc"]
|
33
35
|
t.spec_files = FileList['spec/**/*spec.rb']
|
34
36
|
end
|
35
|
-
|
36
|
-
desc "Generate gemspec"
|
37
|
-
task :gemspec do |t|
|
38
|
-
`rake debug_gem > dbf.gemspec`
|
39
|
-
end
|
data/dbf.gemspec
CHANGED
@@ -1,40 +1,88 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
7
|
s.name = %q{dbf}
|
3
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.10"
|
4
9
|
|
5
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
11
|
s.authors = ["Keith Morrison"]
|
7
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-04}
|
8
13
|
s.default_executable = %q{dbf}
|
9
|
-
s.description = %q{
|
14
|
+
s.description = %q{A small fast library for reading dBase, xBase, Clipper and FoxPro database files.}
|
10
15
|
s.email = %q{keithm@infused.org}
|
11
16
|
s.executables = ["dbf"]
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.markdown"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".autotest",
|
22
|
+
"History.txt",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"bin/dbf",
|
27
|
+
"dbf.gemspec",
|
28
|
+
"lib/dbf.rb",
|
29
|
+
"lib/dbf/column.rb",
|
30
|
+
"lib/dbf/globals.rb",
|
31
|
+
"lib/dbf/record.rb",
|
32
|
+
"lib/dbf/table.rb",
|
33
|
+
"spec/fixtures/dbase_03.dbf",
|
34
|
+
"spec/fixtures/dbase_30.dbf",
|
35
|
+
"spec/fixtures/dbase_30.fpt",
|
36
|
+
"spec/fixtures/dbase_83.dbf",
|
37
|
+
"spec/fixtures/dbase_83.dbt",
|
38
|
+
"spec/fixtures/dbase_83_schema.txt",
|
39
|
+
"spec/fixtures/dbase_8b.dbf",
|
40
|
+
"spec/fixtures/dbase_8b.dbt",
|
41
|
+
"spec/fixtures/dbase_f5.dbf",
|
42
|
+
"spec/fixtures/dbase_f5.fpt",
|
43
|
+
"spec/functional/dbf_shared.rb",
|
44
|
+
"spec/functional/format_03_spec.rb",
|
45
|
+
"spec/functional/format_30_spec.rb",
|
46
|
+
"spec/functional/format_83_spec.rb",
|
47
|
+
"spec/functional/format_8b_spec.rb",
|
48
|
+
"spec/functional/format_f5_spec.rb",
|
49
|
+
"spec/spec_helper.rb",
|
50
|
+
"spec/unit/column_spec.rb",
|
51
|
+
"spec/unit/record_spec.rb",
|
52
|
+
"spec/unit/table_spec.rb"
|
53
|
+
]
|
54
|
+
s.homepage = %q{http://github.com/infused/dbf}
|
55
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
17
56
|
s.require_paths = ["lib"]
|
18
57
|
s.rubyforge_project = %q{dbf}
|
19
|
-
s.rubygems_version = %q{1.3.
|
20
|
-
s.summary = %q{
|
58
|
+
s.rubygems_version = %q{1.3.5}
|
59
|
+
s.summary = %q{Read xBase files}
|
60
|
+
s.test_files = [
|
61
|
+
"spec/functional/dbf_shared.rb",
|
62
|
+
"spec/functional/format_03_spec.rb",
|
63
|
+
"spec/functional/format_30_spec.rb",
|
64
|
+
"spec/functional/format_83_spec.rb",
|
65
|
+
"spec/functional/format_8b_spec.rb",
|
66
|
+
"spec/functional/format_f5_spec.rb",
|
67
|
+
"spec/spec_helper.rb",
|
68
|
+
"spec/unit/column_spec.rb",
|
69
|
+
"spec/unit/record_spec.rb",
|
70
|
+
"spec/unit/table_spec.rb"
|
71
|
+
]
|
21
72
|
|
22
73
|
if s.respond_to? :specification_version then
|
23
74
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version =
|
75
|
+
s.specification_version = 3
|
25
76
|
|
26
77
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
78
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
|
28
79
|
s.add_runtime_dependency(%q<fastercsv>, [">= 1.4.0"])
|
29
|
-
s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
|
30
80
|
else
|
31
81
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
32
82
|
s.add_dependency(%q<fastercsv>, [">= 1.4.0"])
|
33
|
-
s.add_dependency(%q<hoe>, [">= 1.8.2"])
|
34
83
|
end
|
35
84
|
else
|
36
85
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
37
86
|
s.add_dependency(%q<fastercsv>, [">= 1.4.0"])
|
38
|
-
s.add_dependency(%q<hoe>, [">= 1.8.2"])
|
39
87
|
end
|
40
88
|
end
|
data/lib/dbf/table.rb
CHANGED
@@ -3,7 +3,7 @@ module DBF
|
|
3
3
|
class Table
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
attr_reader :column_count # The total number of columns
|
6
|
+
attr_reader :column_count # The total number of columns
|
7
7
|
attr_reader :columns # An array of DBF::Column
|
8
8
|
attr_reader :version # Internal dBase version number
|
9
9
|
attr_reader :last_updated # Last updated datetime
|
@@ -229,14 +229,9 @@ module DBF
|
|
229
229
|
|
230
230
|
def build_db_index
|
231
231
|
@db_index = []
|
232
|
-
@deleted_records = []
|
233
232
|
0.upto(@record_count - 1) do |n|
|
234
233
|
seek_to_record(n)
|
235
|
-
|
236
|
-
@deleted_records << n
|
237
|
-
else
|
238
|
-
@db_index << n
|
239
|
-
end
|
234
|
+
@db_index << n unless deleted_record?
|
240
235
|
end
|
241
236
|
end
|
242
237
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-04 00:00:00 -07:00
|
13
13
|
default_executable: dbf
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,30 +32,20 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.4.0
|
34
34
|
version:
|
35
|
-
|
36
|
-
name: hoe
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 1.8.2
|
44
|
-
version:
|
45
|
-
description: "DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org, www.infused.org> * Official project page: http://rubyforge.org/projects/dbf * API Documentation: http://dbf.rubyforge.org/docs * To report bugs: http://www.rubyforge.org/tracker/?group_id=2009 * Questions: Email keithm@infused.org and put DBF somewhere in the subject line"
|
35
|
+
description: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
|
46
36
|
email: keithm@infused.org
|
47
37
|
executables:
|
48
38
|
- dbf
|
49
39
|
extensions: []
|
50
40
|
|
51
41
|
extra_rdoc_files:
|
52
|
-
-
|
53
|
-
- README.txt
|
42
|
+
- README.markdown
|
54
43
|
files:
|
44
|
+
- .autotest
|
55
45
|
- History.txt
|
56
|
-
-
|
57
|
-
- README.txt
|
46
|
+
- README.markdown
|
58
47
|
- Rakefile
|
48
|
+
- VERSION.yml
|
59
49
|
- bin/dbf
|
60
50
|
- dbf.gemspec
|
61
51
|
- lib/dbf.rb
|
@@ -84,13 +74,12 @@ files:
|
|
84
74
|
- spec/unit/record_spec.rb
|
85
75
|
- spec/unit/table_spec.rb
|
86
76
|
has_rdoc: true
|
87
|
-
homepage: http://github.com/infused/
|
77
|
+
homepage: http://github.com/infused/dbf
|
88
78
|
licenses: []
|
89
79
|
|
90
80
|
post_install_message:
|
91
81
|
rdoc_options:
|
92
|
-
- --
|
93
|
-
- README.txt
|
82
|
+
- --charset=UTF-8
|
94
83
|
require_paths:
|
95
84
|
- lib
|
96
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -110,7 +99,16 @@ requirements: []
|
|
110
99
|
rubyforge_project: dbf
|
111
100
|
rubygems_version: 1.3.5
|
112
101
|
signing_key:
|
113
|
-
specification_version:
|
114
|
-
summary:
|
115
|
-
test_files:
|
116
|
-
|
102
|
+
specification_version: 3
|
103
|
+
summary: Read xBase files
|
104
|
+
test_files:
|
105
|
+
- spec/functional/dbf_shared.rb
|
106
|
+
- spec/functional/format_03_spec.rb
|
107
|
+
- spec/functional/format_30_spec.rb
|
108
|
+
- spec/functional/format_83_spec.rb
|
109
|
+
- spec/functional/format_8b_spec.rb
|
110
|
+
- spec/functional/format_f5_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/unit/column_spec.rb
|
113
|
+
- spec/unit/record_spec.rb
|
114
|
+
- spec/unit/table_spec.rb
|
data/Manifest.txt
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.txt
|
4
|
-
Rakefile
|
5
|
-
bin/dbf
|
6
|
-
dbf.gemspec
|
7
|
-
lib/dbf.rb
|
8
|
-
lib/dbf/column.rb
|
9
|
-
lib/dbf/globals.rb
|
10
|
-
lib/dbf/record.rb
|
11
|
-
lib/dbf/table.rb
|
12
|
-
spec/fixtures/dbase_03.dbf
|
13
|
-
spec/fixtures/dbase_30.dbf
|
14
|
-
spec/fixtures/dbase_30.fpt
|
15
|
-
spec/fixtures/dbase_83.dbf
|
16
|
-
spec/fixtures/dbase_83.dbt
|
17
|
-
spec/fixtures/dbase_83_schema.txt
|
18
|
-
spec/fixtures/dbase_8b.dbf
|
19
|
-
spec/fixtures/dbase_8b.dbt
|
20
|
-
spec/fixtures/dbase_f5.dbf
|
21
|
-
spec/fixtures/dbase_f5.fpt
|
22
|
-
spec/functional/dbf_shared.rb
|
23
|
-
spec/functional/format_03_spec.rb
|
24
|
-
spec/functional/format_30_spec.rb
|
25
|
-
spec/functional/format_83_spec.rb
|
26
|
-
spec/functional/format_8b_spec.rb
|
27
|
-
spec/functional/format_f5_spec.rb
|
28
|
-
spec/spec_helper.rb
|
29
|
-
spec/unit/column_spec.rb
|
30
|
-
spec/unit/record_spec.rb
|
31
|
-
spec/unit/table_spec.rb
|