dbf 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +14 -12
- data/README.md +15 -9
- data/lib/dbf/column/base.rb +9 -1
- data/lib/dbf/table.rb +9 -2
- data/lib/dbf/version.rb +1 -1
- data/spec/dbf/record_spec.rb +15 -0
- metadata +70 -63
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dbf (1.7.
|
5
|
-
fastercsv (~> 1.5.4)
|
4
|
+
dbf (1.7.4)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: http://rubygems.org/
|
9
8
|
specs:
|
10
9
|
diff-lcs (1.1.3)
|
11
|
-
|
10
|
+
json (1.6.5)
|
12
11
|
rake (0.9.2.2)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rspec-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rspec-
|
12
|
+
rdoc (3.12)
|
13
|
+
json (~> 1.4)
|
14
|
+
rspec (2.8.0)
|
15
|
+
rspec-core (~> 2.8.0)
|
16
|
+
rspec-expectations (~> 2.8.0)
|
17
|
+
rspec-mocks (~> 2.8.0)
|
18
|
+
rspec-core (2.8.0)
|
19
|
+
rspec-expectations (2.8.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.8.0)
|
21
22
|
|
22
23
|
PLATFORMS
|
23
24
|
ruby
|
@@ -25,4 +26,5 @@ PLATFORMS
|
|
25
26
|
DEPENDENCIES
|
26
27
|
dbf!
|
27
28
|
rake (~> 0.9.2)
|
28
|
-
|
29
|
+
rdoc (~> 3.11)
|
30
|
+
rspec (~> 2.8.0)
|
data/README.md
CHANGED
@@ -37,16 +37,22 @@ Enumerate all records
|
|
37
37
|
|
38
38
|
Find a single record
|
39
39
|
|
40
|
-
widget.find(6)
|
40
|
+
widget = widgets.find(6)
|
41
|
+
|
42
|
+
Note that find() will return nil if the requested record has been deleted
|
43
|
+
and not yet pruned from the database.
|
44
|
+
|
45
|
+
The value for a attribute can be accessed via element reference in one of three
|
46
|
+
ways
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
widget["SlotNumber"] # original field name in dbf file
|
49
|
+
widget['slot_number'] # underscored field name string
|
50
|
+
widget[:slot_number] # underscored field name symbol
|
51
|
+
|
52
|
+
Get a hash of all attributes. The keys are the original column names.
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
widget.find(4)[:slot_number]
|
54
|
+
widgets.attributes
|
55
|
+
=> {"Name" => "Thing1", "SlotNumber" => 1}
|
50
56
|
|
51
57
|
Search for records using a simple hash format. Multiple search criteria are
|
52
58
|
ANDed. Use the block form if the resulting recordset could be large, otherwise
|
@@ -81,7 +87,7 @@ An example of migrating a DBF book table to ActiveRecord using a migration:
|
|
81
87
|
|
82
88
|
Book.reset_column_information
|
83
89
|
table.each do |record|
|
84
|
-
Book.create(record.
|
90
|
+
Book.create(:title => record.title, :author => record.author)
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
data/lib/dbf/column/base.rb
CHANGED
@@ -96,7 +96,15 @@ module DBF
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def encode_string(value) #nodoc
|
99
|
-
|
99
|
+
if @encoding
|
100
|
+
if String.new.respond_to?(:encoding)
|
101
|
+
value.force_encoding(@encoding).encode(Encoding.default_external, :undef => :replace, :invalid => :replace)
|
102
|
+
else
|
103
|
+
Iconv.conv('UTF-8', @encoding, value)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
value
|
107
|
+
end
|
100
108
|
end
|
101
109
|
|
102
110
|
def schema_data_type #nodoc
|
data/lib/dbf/table.rb
CHANGED
@@ -209,7 +209,14 @@ module DBF
|
|
209
209
|
end
|
210
210
|
|
211
211
|
def supports_encoding?
|
212
|
-
String.new.respond_to?
|
212
|
+
String.new.respond_to?(:encoding)
|
213
|
+
end
|
214
|
+
|
215
|
+
def supports_iconv?
|
216
|
+
require 'iconv'
|
217
|
+
true
|
218
|
+
rescue
|
219
|
+
false
|
213
220
|
end
|
214
221
|
|
215
222
|
def foxpro?
|
@@ -281,7 +288,7 @@ module DBF
|
|
281
288
|
def get_header_info #nodoc
|
282
289
|
@data.rewind
|
283
290
|
@version, @record_count, @header_length, @record_length, @encoding_key = read_header
|
284
|
-
@encoding = ENCODINGS[@encoding_key] if supports_encoding?
|
291
|
+
@encoding = ENCODINGS[@encoding_key] if supports_encoding? || supports_iconv?
|
285
292
|
end
|
286
293
|
|
287
294
|
def read_header #nodoc
|
data/lib/dbf/version.rb
CHANGED
data/spec/dbf/record_spec.rb
CHANGED
@@ -62,4 +62,19 @@ describe DBF::Record do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
describe '#attributes' do
|
67
|
+
let(:table) { DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"}
|
68
|
+
let(:record) { table.find(0) }
|
69
|
+
|
70
|
+
it 'is a hash of attribute name/value pairs' do
|
71
|
+
record.attributes.should be_a(Hash)
|
72
|
+
record.attributes['CHARACTER'] == 'One'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'has only original field names as keys' do
|
76
|
+
original_field_names = %w(CHARACTER DATE FLOAT LOGICAL MEMO NUMERICAL)
|
77
|
+
record.attributes.keys.sort.should == original_field_names
|
78
|
+
end
|
79
|
+
end
|
65
80
|
end
|
metadata
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbf
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 2.0.1
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Keith Morrison
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-09-28 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: fastercsv
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.5.4
|
22
|
-
type: :runtime
|
23
22
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
requirements:
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
27
25
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 5
|
30
|
+
- 4
|
29
31
|
version: 1.5.4
|
30
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
31
35
|
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 2.9.0
|
38
|
-
type: :development
|
39
36
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
43
39
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 9
|
44
|
+
- 0
|
45
45
|
version: 2.9.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rake
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.9.2
|
54
46
|
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
55
50
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
requirements:
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
59
53
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 2
|
61
59
|
version: 0.9.2
|
62
|
-
|
63
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
|
64
63
|
email: keithm@infused.org
|
65
|
-
executables:
|
64
|
+
executables:
|
66
65
|
- dbf
|
67
66
|
extensions: []
|
68
|
-
|
67
|
+
|
68
|
+
extra_rdoc_files:
|
69
69
|
- README.md
|
70
70
|
- CHANGELOG.md
|
71
71
|
- MIT-LICENSE
|
72
|
-
files:
|
72
|
+
files:
|
73
73
|
- CHANGELOG.md
|
74
74
|
- Gemfile
|
75
75
|
- Gemfile.lock
|
@@ -109,32 +109,39 @@ files:
|
|
109
109
|
- spec/rvm_ruby_runner.rb
|
110
110
|
- spec/spec_helper.rb
|
111
111
|
- dbf.gemspec
|
112
|
+
has_rdoc: true
|
112
113
|
homepage: http://github.com/infused/dbf
|
113
114
|
licenses: []
|
115
|
+
|
114
116
|
post_install_message:
|
115
|
-
rdoc_options:
|
117
|
+
rdoc_options:
|
116
118
|
- --charset=UTF-8
|
117
|
-
require_paths:
|
119
|
+
require_paths:
|
118
120
|
- lib
|
119
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 1
|
134
|
+
- 3
|
135
|
+
- 0
|
130
136
|
version: 1.3.0
|
131
137
|
requirements: []
|
138
|
+
|
132
139
|
rubyforge_project:
|
133
|
-
rubygems_version: 1.
|
140
|
+
rubygems_version: 1.3.6
|
134
141
|
signing_key:
|
135
142
|
specification_version: 3
|
136
143
|
summary: Read xBase files
|
137
|
-
test_files:
|
144
|
+
test_files:
|
138
145
|
- spec/dbf/column_spec.rb
|
139
146
|
- spec/dbf/file_formats_spec.rb
|
140
147
|
- spec/dbf/record_spec.rb
|