dbf 0.5.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: dbf
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.4
7
- date: 2007-06-22 00:00:00 -07:00
6
+ version: 1.0.0
7
+ date: 2007-06-27 00:00:00 -07:00
8
8
  summary: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
9
9
  require_paths:
10
10
  - lib
@@ -29,7 +29,6 @@ post_install_message:
29
29
  authors:
30
30
  - Keith Morrison
31
31
  files:
32
- - .DS_Store
33
32
  - History.txt
34
33
  - Manifest.txt
35
34
  - README.txt
@@ -38,12 +37,10 @@ files:
38
37
  - benchmarks/seek_benchmark.rb
39
38
  - bin/dbf
40
39
  - lib/dbf.rb
41
- - lib/dbf/field.rb
40
+ - lib/dbf/column.rb
42
41
  - lib/dbf/globals.rb
43
- - lib/dbf/reader.rb
44
42
  - lib/dbf/record.rb
45
- - spec/.DS_Store
46
- - spec/fixtures/.DS_Store
43
+ - lib/dbf/table.rb
47
44
  - spec/fixtures/dbase_03.dbf
48
45
  - spec/fixtures/dbase_30.dbf
49
46
  - spec/fixtures/dbase_30.fpt
@@ -61,9 +58,9 @@ files:
61
58
  - spec/functional/format_8b_spec.rb
62
59
  - spec/functional/format_f5_spec.rb
63
60
  - spec/spec_helper.rb
64
- - spec/unit/field_spec.rb
65
- - spec/unit/reader_spec.rb
61
+ - spec/unit/column_spec.rb
66
62
  - spec/unit/record_spec.rb
63
+ - spec/unit/table_spec.rb
67
64
  test_files: []
68
65
 
69
66
  rdoc_options:
data/.DS_Store DELETED
Binary file
Binary file
Binary file
@@ -1,34 +0,0 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe DBF::Field, "when initialized" do
4
-
5
- before(:each) do
6
- @field = DBF::Field.new "FieldName", "N", 1, 0
7
- end
8
-
9
- it "should set the #name accessor" do
10
- @field.name.should == "FieldName"
11
- end
12
-
13
- it "should set the #type accessor" do
14
- @field.type.should == "N"
15
- end
16
-
17
- it "should set the #length accessor" do
18
- @field.length.should == 1
19
- end
20
-
21
- it "should set the #decimal accessor" do
22
- @field.decimal.should == 0
23
- end
24
-
25
- it "should raise an error if length is greater than 0" do
26
- lambda { field = DBF::Field.new "FieldName", "N", -1, 0 }.should raise_error(DBF::FieldLengthError)
27
- end
28
-
29
- it "should strip null characters from the name" do
30
- field = DBF::Field.new "Field\0Name\0", "N", 1, 0
31
- field.name.should == "FieldName"
32
- end
33
-
34
- end
@@ -1,173 +0,0 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
- describe DBF::Reader, "when initialized" do
4
-
5
- before(:all) do
6
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
7
- end
8
-
9
- it "should load the data file" do
10
- @reader.instance_eval("@data_file").should be_kind_of(File)
11
- end
12
-
13
- it "should locate load the memo file" do
14
- @reader.has_memo_file?.should be_true
15
- @reader.instance_eval("@memo_file").should be_kind_of(File)
16
- end
17
-
18
- it "should determine the memo file format" do
19
- @reader.memo_file_format.should == :dbt
20
- end
21
-
22
- it "should determine the memo block size" do
23
- @reader.memo_block_size.should == 512
24
- end
25
-
26
- it "should default to loading all records into memory" do
27
- @reader.in_memory?.should be_true
28
- end
29
-
30
- it "should determine the number of fields in each record" do
31
- @reader.fields.size.should == 15
32
- end
33
-
34
- it "should determine the number of records in the database" do
35
- @reader.record_count.should == 67
36
- end
37
-
38
- it "should determine the database version" do
39
- @reader.version.should == "83"
40
- end
41
-
42
- it "should set the in_memory option" do
43
- @reader.in_memory?.should be_true
44
- reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf", :in_memory => false
45
- reader.in_memory?.should be_false
46
- end
47
-
48
- end
49
-
50
- describe DBF::Reader, "when the in_memory flag is true" do
51
-
52
- before(:each) do
53
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
54
- end
55
-
56
- it "should build the records array from disk only on the first request" do
57
- @reader.expects(:get_all_records_from_file).at_most_once.returns([])
58
- 3.times { @reader.records }
59
- end
60
-
61
- it "should read from the records array when using the record() method" do
62
- @reader.expects(:get_all_records_from_file).at_most_once.returns([])
63
- @reader.expects(:get_record_from_file).never
64
- @reader.expects(:records).times(2).returns([])
65
- @reader.record(1)
66
- @reader.record(10)
67
- end
68
-
69
- end
70
-
71
- describe DBF::Reader, "when the in_memory flag is false" do
72
-
73
- it "should read the records from disk on every request" do
74
- reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf", :in_memory => false
75
- reader.expects(:get_all_records_from_file).times(3).returns([])
76
- 3.times { reader.records }
77
- end
78
- end
79
-
80
- describe DBF::Reader, "schema" do
81
-
82
- it "should match test schema " do
83
- reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
84
- control_schema = File.read(File.dirname(__FILE__) + '/../fixtures/dbase_83_schema.txt')
85
-
86
- reader.schema.should == control_schema
87
- end
88
-
89
- end
90
-
91
- describe DBF::Reader, "find(index)" do
92
-
93
- before(:all) do
94
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
95
- end
96
-
97
- it "should return the correct record" do
98
- @reader.find(5).should == @reader.record(5)
99
- end
100
-
101
- it "should raise an error if options are not empty" do
102
- lambda { @reader.find(5, :name => 'test') }.should raise_error(ArgumentError)
103
- end
104
-
105
- end
106
-
107
- describe DBF::Reader, "find(:all)" do
108
-
109
- before(:all) do
110
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
111
- end
112
-
113
- it "should return all records if options are empty" do
114
- @reader.find(:all).should == @reader.records
115
- end
116
-
117
- it "should return matching records when used with options" do
118
- @reader.find(:all, "WEIGHT" => 0.0).should == @reader.records.select {|r| r["WEIGHT"] == 0.0}
119
- end
120
-
121
- it "with multiple options should search for all search terms as if using AND" do
122
- @reader.find(:all, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg").should == []
123
- end
124
- end
125
-
126
- describe DBF::Reader, "find(:first)" do
127
-
128
- before(:all) do
129
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
130
- end
131
-
132
- it "should return the first record if options are empty" do
133
- @reader.find(:first).should == @reader.records.first
134
- end
135
-
136
- it "should return the first matching record when used with options" do
137
- @reader.find(:first, "CODE" => "C").should == @reader.record(5)
138
- end
139
-
140
- it "with multiple options should search for all search terms as if using AND" do
141
- @reader.find(:first, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg").should be_nil
142
- end
143
- end
144
-
145
- describe DBF::Reader do
146
-
147
- before(:each) do
148
- @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
149
- end
150
-
151
- it "should reload all data when sent #reload!" do
152
- @reader.records
153
- @reader.instance_eval("@records").should be_kind_of(Array)
154
- @reader.reload!
155
- @reader.instance_eval("@records").should be_nil
156
- end
157
-
158
- it "should return a DBF::Field object when sent #field with a valid field_name given as a string or symbol" do
159
- @reader.field("IMAGE").should be_kind_of(DBF::Field)
160
- @reader.field(:IMAGE).should be_kind_of(DBF::Field)
161
- end
162
-
163
- it "should return nil when sent #field with an invalid field_name given as a string or symbol" do
164
- @reader.field("NOTANIMAGE").should be_nil
165
- @reader.field(:NOTANIMAGE).should be_nil
166
- end
167
-
168
- it "should return a text description of the database type when sent #version_description" do
169
- @reader.version_description.should == "dBase III with memo file"
170
- end
171
-
172
- end
173
-