dbf 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +59 -0
- data/doc/README +37 -0
- data/lib/dbf/reader.rb +10 -1
- metadata +5 -3
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
Gem::manage_gems
|
6
|
+
|
7
|
+
PKG_NAME = "dbf"
|
8
|
+
PKG_VERSION = "0.4.3"
|
9
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.name = PKG_NAME
|
13
|
+
s.version = PKG_VERSION
|
14
|
+
s.author = "Keith Morrison"
|
15
|
+
s.email = "keithm@infused.org"
|
16
|
+
s.homepage = "http://www.infused.org"
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
s.summary = "A library for reading dBase (or xBase, Clipper, Foxpro, etc) database files"
|
19
|
+
s.files = FileList["{lib,test}/**/*", "doc/README", "Rakefile"].to_a
|
20
|
+
s.require_path = "lib"
|
21
|
+
s.has_rdoc = true
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Build Gem'
|
25
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
26
|
+
pkg.need_zip = true
|
27
|
+
pkg.need_tar = true
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run tests'
|
31
|
+
task :default => :test
|
32
|
+
|
33
|
+
desc 'Run tests'
|
34
|
+
Rake::TestTask.new :test do |t|
|
35
|
+
t.libs << "test"
|
36
|
+
t.pattern = 'test/*_test.rb'
|
37
|
+
t.verbose = true
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Generate documentation for the application"
|
41
|
+
Rake::RDocTask.new("rdoc") do |t|
|
42
|
+
t.rdoc_dir = 'doc/app'
|
43
|
+
t.title = "Ruby DBF Library"
|
44
|
+
t.options << '--line-numbers' << '--inline-source'
|
45
|
+
t.rdoc_files.include('doc/README')
|
46
|
+
t.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Creates a release tag"
|
50
|
+
task :create_release_tag do |t|
|
51
|
+
puts "Creating svn+ssh://infused@rubyforge.org/var/svn/dbf/tags/RELEASE_#{PKG_VERSION.gsub('.', '_')}"
|
52
|
+
`svn copy . svn+ssh://infused@rubyforge.org/var/svn/dbf/tags/RELEASE_#{PKG_VERSION.gsub('.', '_')} -m "Creating RELEASE_#{PKG_VERSION.gsub('.', '_')} tag"`
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Removes the current release tag"
|
56
|
+
task :remove_release_tag do |t|
|
57
|
+
puts "Removing svn+ssh://infused@rubyforge.org/var/svn/dbf/tags/RELEASE_#{PKG_VERSION.gsub('.', '_')}"
|
58
|
+
`svn remove svn+ssh://infused@rubyforge.org/var/svn/dbf/tags/RELEASE_#{PKG_VERSION.gsub('.', '_')} -m "Removing RELEASE_#{PKG_VERSION.gsub('.', '_')} tag"`
|
59
|
+
end
|
data/doc/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= DBF
|
2
|
+
A dBase I/O library.
|
3
|
+
|
4
|
+
== Features
|
5
|
+
|
6
|
+
* No external dependencies
|
7
|
+
* DB fields are type cast
|
8
|
+
* Date/Time fields are returned as either a Time or Date object. Date
|
9
|
+
will only be used if the date is outside the range for Time.
|
10
|
+
|
11
|
+
== Limitations
|
12
|
+
|
13
|
+
* Writing to the db has not been implemented yet
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
reader = DBF::Reader.new("old_data.dbf")
|
18
|
+
|
19
|
+
reader.records.each do |record|
|
20
|
+
puts record['name']
|
21
|
+
puts record['email']
|
22
|
+
end
|
23
|
+
|
24
|
+
puts reader.records[4]['name']
|
25
|
+
puts reader.record(4)['name']
|
26
|
+
|
27
|
+
=== A note on record vs. records
|
28
|
+
|
29
|
+
DBF::Reader#records is an in-memory array of all rows in the database. All
|
30
|
+
rows are loaded the first time that the method is called. Subsequent calls
|
31
|
+
retrieve the row from memory.
|
32
|
+
|
33
|
+
DBF::Reader#record retrieves the requested row from the database each time
|
34
|
+
it is called.
|
35
|
+
|
36
|
+
Using records is probably faster most of the time. Record is more appropriate
|
37
|
+
for very large databases where you don't want the whole db loaded into memory.
|
data/lib/dbf/reader.rb
CHANGED
@@ -150,7 +150,16 @@ module DBF
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def get_field_descriptors
|
153
|
-
@fields =
|
153
|
+
@fields = []
|
154
|
+
@field_count.times do
|
155
|
+
name, type, length, decimal = @data_file.read(32).unpack('a10xax4CC')
|
156
|
+
if length > 0 && !name.strip.empty?
|
157
|
+
@fields << Field.new(name.strip, type, length, decimal)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
# adjust field count
|
161
|
+
@field_count = @fields.size
|
162
|
+
@fields
|
154
163
|
end
|
155
164
|
|
156
165
|
def get_memo_header_info
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.1
|
3
3
|
specification_version: 1
|
4
4
|
name: dbf
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date:
|
6
|
+
version: 0.4.3
|
7
|
+
date: 2007-01-31 00:00:00 -08:00
|
8
8
|
summary: A library for reading dBase (or xBase, Clipper, Foxpro, etc) database files
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -40,6 +40,8 @@ files:
|
|
40
40
|
- test/databases/dbase_iii.dbf
|
41
41
|
- test/databases/foxpro.dbf
|
42
42
|
- test/databases/foxpro.fpt
|
43
|
+
- doc/README
|
44
|
+
- Rakefile
|
43
45
|
test_files: []
|
44
46
|
|
45
47
|
rdoc_options: []
|