dbf 1.2.0 → 1.2.1
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/History.txt +8 -0
- data/README.markdown +18 -10
- data/VERSION.yml +1 -1
- data/dbf.gemspec +3 -3
- data/lib/dbf/column.rb +11 -1
- data/lib/dbf/table.rb +11 -5
- data/spec/unit/column_spec.rb +12 -0
- data/spec/unit/record_spec.rb +1 -1
- data/spec/unit/table_spec.rb +15 -0
- metadata +28 -13
data/History.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
# DBF
|
2
2
|
|
3
|
-
DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro
|
3
|
+
DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro
|
4
|
+
database files
|
4
5
|
|
5
6
|
* Project page: <http://github.com/infused/dbf>
|
6
7
|
* API Documentation: <http://rdoc.info/projects/infused/dbf>
|
7
8
|
* Report bugs: <http://github.com/infused/dbf/issues>
|
8
|
-
* Questions: Email <mailto:keithm@infused.org> and put DBF somewhere in the
|
9
|
+
* Questions: Email <mailto:keithm@infused.org> and put DBF somewhere in the
|
10
|
+
subject line
|
9
11
|
|
10
12
|
## Features
|
11
13
|
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
|
14
|
+
* Fields are type cast to the appropriate Ruby types
|
15
|
+
* ActiveRecord style finder methods
|
16
|
+
* Ability to dump the database schema in the portable ActiveRecord::Schema
|
17
|
+
format
|
16
18
|
* Ruby 1.9.1 compatible
|
17
19
|
|
18
20
|
## Installation
|
@@ -42,6 +44,8 @@ Load a single record using <tt>record</tt> or <tt>find</tt>
|
|
42
44
|
|
43
45
|
Attributes can also be accessed through the attributes hash in original or
|
44
46
|
underscored form or as an accessor method using the underscored name.
|
47
|
+
(Note that record() will return nil if the requested record has been
|
48
|
+
deleted and not yet pruned from the database)
|
45
49
|
|
46
50
|
table.record(4).attributes["PhoneBook"]
|
47
51
|
table.record(4).attributes["phone_book"]
|
@@ -53,7 +57,10 @@ otherwise all records will be loaded into memory.
|
|
53
57
|
|
54
58
|
# find all records with first_name equal to Keith
|
55
59
|
table.find(:all, :first_name => 'Keith') do |record|
|
56
|
-
|
60
|
+
# the record will be nil if deleted and not yet pruned from the database
|
61
|
+
if record
|
62
|
+
puts record.last_name
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
# find all records with first_name equal to Keith and last_name equal
|
@@ -99,16 +106,17 @@ A small command-line utility called dbf is installed along with the gem.
|
|
99
106
|
-s = print summary information
|
100
107
|
-a = create an ActiveRecord::Schema
|
101
108
|
|
102
|
-
## Limitations
|
109
|
+
## Limitations
|
103
110
|
|
104
111
|
* DBF is read-only
|
105
|
-
*
|
112
|
+
* index files are not utilized
|
106
113
|
|
107
114
|
## License
|
108
115
|
|
109
116
|
(The MIT Licence)
|
110
117
|
|
111
|
-
Copyright (c) 2006-
|
118
|
+
Copyright (c) 2006-2010 Keith Morrison <mailto:keithm@infused.org>,
|
119
|
+
<http://www.infused.org>.
|
112
120
|
|
113
121
|
Permission is hereby granted, free of charge, to any person
|
114
122
|
obtaining a copy of this software and associated documentation
|
data/VERSION.yml
CHANGED
data/dbf.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dbf}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Keith Morrison"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-30}
|
13
13
|
s.default_executable = %q{dbf}
|
14
14
|
s.description = %q{A small fast library for reading dBase, xBase, Clipper and FoxPro database files.}
|
15
15
|
s.email = %q{keithm@infused.org}
|
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.homepage = %q{http://github.com/infused/dbf}
|
56
56
|
s.rdoc_options = ["--charset=UTF-8"]
|
57
57
|
s.require_paths = ["lib"]
|
58
|
-
s.rubygems_version = %q{1.3.
|
58
|
+
s.rubygems_version = %q{1.3.6}
|
59
59
|
s.summary = %q{Read xBase files}
|
60
60
|
s.test_files = [
|
61
61
|
"spec/functional/dbf_shared.rb",
|
data/lib/dbf/column.rb
CHANGED
@@ -28,6 +28,8 @@ module DBF
|
|
28
28
|
case type
|
29
29
|
when 'N' # number
|
30
30
|
unpack_number(value)
|
31
|
+
when 'F' # float
|
32
|
+
unpack_float(value)
|
31
33
|
when 'D' # date
|
32
34
|
value.to_date unless value.blank?
|
33
35
|
when 'L' # logical
|
@@ -59,6 +61,14 @@ module DBF
|
|
59
61
|
decimal.zero? ? unpack_integer(value) : value.to_f
|
60
62
|
end
|
61
63
|
|
64
|
+
# Decode a float value
|
65
|
+
#
|
66
|
+
# @param [String] value
|
67
|
+
# @return [Float]
|
68
|
+
def unpack_float(value)
|
69
|
+
value.to_f
|
70
|
+
end
|
71
|
+
|
62
72
|
# Decode an integer
|
63
73
|
#
|
64
74
|
# @param [String] value
|
@@ -87,7 +97,7 @@ module DBF
|
|
87
97
|
# @return [String]
|
88
98
|
def schema_data_type
|
89
99
|
case type
|
90
|
-
when "N"
|
100
|
+
when "N", "F"
|
91
101
|
decimal > 0 ? ":float" : ":integer"
|
92
102
|
when "I"
|
93
103
|
":integer"
|
data/lib/dbf/table.rb
CHANGED
@@ -61,17 +61,19 @@ module DBF
|
|
61
61
|
def each
|
62
62
|
0.upto(@record_count - 1) do |n|
|
63
63
|
seek_to_record(n)
|
64
|
-
yield
|
64
|
+
yield current_record
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
# Retrieve a record by index number
|
68
|
+
# Retrieve a record by index number.
|
69
|
+
# The record will be nil if it has been deleted, but not yet pruned from
|
70
|
+
# the database.
|
69
71
|
#
|
70
72
|
# @param [Fixnum] index
|
71
|
-
# @return [DBF::Record]
|
73
|
+
# @return [DBF::Record, NilClass]
|
72
74
|
def record(index)
|
73
75
|
seek_to_record(index)
|
74
|
-
|
76
|
+
current_record
|
75
77
|
end
|
76
78
|
|
77
79
|
alias_method :row, :record
|
@@ -162,7 +164,7 @@ module DBF
|
|
162
164
|
#
|
163
165
|
# @param [Fixnum, Symbol] command
|
164
166
|
# @param [optional, Hash] options Hash of search parameters
|
165
|
-
# @yield [optional, DBF::Record]
|
167
|
+
# @yield [optional, DBF::Record, NilClass]
|
166
168
|
def find(command, options = {}, &block)
|
167
169
|
case command
|
168
170
|
when Fixnum
|
@@ -248,6 +250,10 @@ module DBF
|
|
248
250
|
@data.read(1).unpack('a') == ['*']
|
249
251
|
end
|
250
252
|
|
253
|
+
def current_record
|
254
|
+
deleted_record? ? nil : DBF::Record.new(self)
|
255
|
+
end
|
256
|
+
|
251
257
|
# Determine database version, record count, header length and record length
|
252
258
|
def get_header_info
|
253
259
|
@data.rewind
|
data/spec/unit/column_spec.rb
CHANGED
@@ -45,6 +45,18 @@ describe DBF::Column do
|
|
45
45
|
column = DBF::Column.new "ColumnName", "N", 3, 0
|
46
46
|
column.type_cast(value).should == 135
|
47
47
|
end
|
48
|
+
|
49
|
+
it "should cast numbers with decimals to Float" do
|
50
|
+
value = "13.5"
|
51
|
+
column = DBF::Column.new "ColumnName", "N", 2, 1
|
52
|
+
column.type_cast(value).should == 13.5
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should cast float numbers to Float" do
|
56
|
+
value = "135"
|
57
|
+
column = DBF::Column.new "ColumnName", "F", 3, 0
|
58
|
+
column.type_cast(value).should == 135.0
|
59
|
+
end
|
48
60
|
|
49
61
|
it "should cast :integer to Integer" do
|
50
62
|
value = "135"
|
data/spec/unit/record_spec.rb
CHANGED
@@ -89,7 +89,7 @@ describe DBF::Record do
|
|
89
89
|
it 'should return an ordered array of attribute values' do
|
90
90
|
table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"
|
91
91
|
record = table.record(9)
|
92
|
-
record.to_a.should == ["Ten records stored in this database", 10.0, nil, false,
|
92
|
+
record.to_a.should == ["Ten records stored in this database", 10.0, nil, false, 0.1, nil]
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/spec/unit/table_spec.rb
CHANGED
@@ -136,6 +136,21 @@ describe DBF::Table do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
describe "#current_record" do
|
140
|
+
before do
|
141
|
+
@table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return nil for deleted records" do
|
145
|
+
@table.stub!(:deleted_record?).and_return(true)
|
146
|
+
@table.record(0).should be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should return a DBF::Record' do
|
150
|
+
@table.record(0).should be_kind_of(DBF::Record)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
139
154
|
describe "#find" do
|
140
155
|
describe "with index" do
|
141
156
|
before do
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
version: 1.2.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Keith Morrison
|
@@ -9,29 +14,37 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-30 00:00:00 -07:00
|
13
18
|
default_executable: dbf
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: activesupport
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 1
|
30
|
+
- 0
|
23
31
|
version: 2.1.0
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: fastercsv
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 4
|
44
|
+
- 0
|
33
45
|
version: 1.4.0
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
description: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
|
36
49
|
email: keithm@infused.org
|
37
50
|
executables:
|
@@ -87,18 +100,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
100
|
requirements:
|
88
101
|
- - ">="
|
89
102
|
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
90
105
|
version: "0"
|
91
|
-
version:
|
92
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
96
112
|
version: "0"
|
97
|
-
version:
|
98
113
|
requirements: []
|
99
114
|
|
100
115
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.6
|
102
117
|
signing_key:
|
103
118
|
specification_version: 3
|
104
119
|
summary: Read xBase files
|