dbf 3.1.1 → 3.1.2
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +55 -45
- data/LICENSE +1 -1
- data/README.md +4 -4
- data/Rakefile +4 -4
- data/bin/dbf +10 -10
- data/lib/dbf/column.rb +9 -35
- data/lib/dbf/column_type.rb +1 -1
- data/lib/dbf/database/foxpro.rb +9 -10
- data/lib/dbf/encodings.rb +2 -2
- data/lib/dbf/memo/base.rb +4 -4
- data/lib/dbf/memo/dbase3.rb +1 -1
- data/lib/dbf/memo/dbase4.rb +1 -1
- data/lib/dbf/memo/foxpro.rb +2 -2
- data/lib/dbf/record.rb +12 -19
- data/lib/dbf/schema.rb +42 -33
- data/lib/dbf/table.rb +37 -30
- data/lib/dbf/version.rb +1 -1
- data/spec/dbf/column_spec.rb +1 -1
- data/spec/dbf/database_spec.rb +2 -2
- data/spec/dbf/file_formats_spec.rb +56 -56
- data/spec/dbf/record_spec.rb +6 -7
- data/spec/dbf/table_spec.rb +34 -50
- data/spec/fixtures/{dbase_83_schema.txt → dbase_83_schema_ar.txt} +0 -0
- data/spec/fixtures/dbase_83_schema_sq.txt +21 -0
- data/spec/fixtures/dbase_83_schema_sq_lim.txt +21 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2701f07f7f1de7cf433af7589ddab5e0d63d465735e1bf6e3856ab26246cb40b
|
4
|
+
data.tar.gz: 788b16069d991e4a0d56fa776d8a52911d3acbc7c32c583e20651977d1189b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df157ab067bd42bf9dc2b875630e2fcbaa378292cd480bc638c83a0b5aca4001d9fccbc1ab6604dd940d74837b512ea9f997c0f16c9aaf6d8837c1a5fd38eaa
|
7
|
+
data.tar.gz: cd9f715b341ac1f696ba0f25183af91a64dda196ae6fbe48f81e595aacdffe677eca01826106b933d2c9abf067dfb570fa57c146f7da0695764e83f0fa3996f4
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dbf (3.1.
|
4
|
+
dbf (3.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
ast (2.3.0)
|
10
|
+
awesome_print (1.8.0)
|
11
|
+
byebug (9.1.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
ffi (1.9.18)
|
14
15
|
formatador (0.2.5)
|
15
|
-
guard (2.
|
16
|
+
guard (2.14.1)
|
16
17
|
formatador (>= 0.2.4)
|
17
|
-
listen (>= 2.7,
|
18
|
+
listen (>= 2.7, < 4.0)
|
18
19
|
lumberjack (~> 1.0)
|
19
20
|
nenv (~> 0.1)
|
20
21
|
notiffany (~> 0.0)
|
@@ -22,62 +23,71 @@ GEM
|
|
22
23
|
shellany (~> 0.0)
|
23
24
|
thor (>= 0.18.1)
|
24
25
|
guard-compat (1.2.1)
|
25
|
-
guard-rspec (4.
|
26
|
+
guard-rspec (4.7.3)
|
26
27
|
guard (~> 2.1)
|
27
28
|
guard-compat (~> 1.1)
|
28
29
|
rspec (>= 2.99.0, < 4.0)
|
29
|
-
listen (3.
|
30
|
-
rb-fsevent (>= 0.9.
|
31
|
-
rb-inotify (>= 0.9)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
listen (3.1.5)
|
31
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
32
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
33
|
+
ruby_dep (~> 1.2)
|
34
|
+
lumberjack (1.0.12)
|
35
|
+
method_source (0.9.0)
|
36
|
+
nenv (0.3.0)
|
37
|
+
notiffany (0.1.1)
|
36
38
|
nenv (~> 0.1)
|
37
39
|
shellany (~> 0.0)
|
38
|
-
|
40
|
+
parallel (1.12.0)
|
41
|
+
parser (2.4.0.2)
|
42
|
+
ast (~> 2.3)
|
43
|
+
powerpack (0.1.1)
|
44
|
+
pry (0.11.3)
|
39
45
|
coderay (~> 1.1.0)
|
40
|
-
method_source (~> 0.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
rspec (3.
|
52
|
-
rspec-
|
53
|
-
|
54
|
-
rspec-mocks (~> 3.4.0)
|
55
|
-
rspec-core (3.4.1)
|
56
|
-
rspec-support (~> 3.4.0)
|
57
|
-
rspec-expectations (3.4.0)
|
46
|
+
method_source (~> 0.9.0)
|
47
|
+
rainbow (2.2.2)
|
48
|
+
rake
|
49
|
+
rake (12.3.0)
|
50
|
+
rb-fsevent (0.10.2)
|
51
|
+
rb-inotify (0.9.10)
|
52
|
+
ffi (>= 0.5.0, < 2)
|
53
|
+
rspec (3.7.0)
|
54
|
+
rspec-core (~> 3.7.0)
|
55
|
+
rspec-expectations (~> 3.7.0)
|
56
|
+
rspec-mocks (~> 3.7.0)
|
57
|
+
rspec-core (3.7.0)
|
58
|
+
rspec-support (~> 3.7.0)
|
59
|
+
rspec-expectations (3.7.0)
|
58
60
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-mocks (3.
|
61
|
+
rspec-support (~> 3.7.0)
|
62
|
+
rspec-mocks (3.7.0)
|
61
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-support (3.
|
64
|
+
rspec-support (~> 3.7.0)
|
65
|
+
rspec-support (3.7.0)
|
66
|
+
rubocop (0.51.0)
|
67
|
+
parallel (~> 1.10)
|
68
|
+
parser (>= 2.3.3.1, < 3.0)
|
69
|
+
powerpack (~> 0.1)
|
70
|
+
rainbow (>= 2.2.2, < 3.0)
|
71
|
+
ruby-progressbar (~> 1.7)
|
72
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
73
|
+
ruby-progressbar (1.9.0)
|
74
|
+
ruby_dep (1.5.0)
|
64
75
|
shellany (0.0.1)
|
65
|
-
|
66
|
-
|
67
|
-
ffi
|
68
|
-
thor (0.19.1)
|
76
|
+
thor (0.20.0)
|
77
|
+
unicode-display_width (1.3.0)
|
69
78
|
|
70
79
|
PLATFORMS
|
71
|
-
java
|
72
80
|
ruby
|
73
81
|
|
74
82
|
DEPENDENCIES
|
83
|
+
awesome_print
|
75
84
|
byebug
|
76
85
|
dbf!
|
77
86
|
guard
|
78
87
|
guard-rspec
|
79
88
|
rake
|
80
89
|
rspec
|
90
|
+
rubocop
|
81
91
|
|
82
92
|
BUNDLED WITH
|
83
|
-
1.
|
93
|
+
1.16.1
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# DBF
|
2
2
|
[](https://rubygems.org/gems/dbf)
|
3
3
|
[](http://travis-ci.org/infused/dbf)
|
4
|
-
[](https://codeclimate.com/github/infused/dbf)
|
5
|
+
[](https://codeclimate.com/github/infused/dbf)
|
6
6
|
[](https://gemnasium.com/infused/dbf)
|
7
7
|
[](https://rubygems.org/gems/dbf/)
|
8
8
|
|
@@ -22,7 +22,7 @@ NOTE: beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If
|
|
22
22
|
|
23
23
|
DBF is tested to work with the following versions of Ruby:
|
24
24
|
|
25
|
-
* MRI Ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x, 2.4.x
|
25
|
+
* MRI Ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x
|
26
26
|
* JRuby 1.7.x
|
27
27
|
|
28
28
|
## Installation
|
@@ -272,7 +272,7 @@ for a full list of supported column types.
|
|
272
272
|
|
273
273
|
## License
|
274
274
|
|
275
|
-
Copyright (c) 2006-
|
275
|
+
Copyright (c) 2006-2018 Keith Morrison <<keithm@infused.org>>
|
276
276
|
|
277
277
|
Permission is hereby granted, free of charge, to any person
|
278
278
|
obtaining a copy of this software and associated documentation
|
data/Rakefile
CHANGED
@@ -3,16 +3,16 @@ Bundler.setup(:default, :development)
|
|
3
3
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
RSpec::Core::RakeTask.new :spec do |t|
|
6
|
-
t.rspec_opts = %w
|
6
|
+
t.rspec_opts = %w[--color]
|
7
7
|
end
|
8
8
|
|
9
9
|
RSpec::Core::RakeTask.new :specdoc do |t|
|
10
|
-
t.rspec_opts = %w
|
10
|
+
t.rspec_opts = %w[-fl]
|
11
11
|
end
|
12
12
|
|
13
13
|
task default: :spec
|
14
14
|
|
15
|
-
desc
|
15
|
+
desc 'Open an irb session preloaded with this library'
|
16
16
|
task :console do
|
17
|
-
sh
|
17
|
+
sh 'irb -rubygems -I lib -r dbf.rb'
|
18
18
|
end
|
data/bin/dbf
CHANGED
@@ -11,16 +11,16 @@ if params['v']
|
|
11
11
|
|
12
12
|
elsif params['h'] then
|
13
13
|
puts "usage: #{File.basename(__FILE__)} [-h|-s|-a|-c|-r] filename"
|
14
|
-
puts
|
15
|
-
puts
|
16
|
-
puts
|
17
|
-
puts
|
18
|
-
puts
|
19
|
-
puts
|
14
|
+
puts ' -h = print this message'
|
15
|
+
puts ' -v = print the DBF gem version'
|
16
|
+
puts ' -s = print summary information'
|
17
|
+
puts ' -a = create an ActiveRecord::Schema'
|
18
|
+
puts ' -r = create a Sequel migration'
|
19
|
+
puts ' -c = create a CSV file'
|
20
20
|
else
|
21
21
|
|
22
22
|
filename = ARGV.shift
|
23
|
-
abort
|
23
|
+
abort 'You must supply a filename on the command line' unless filename
|
24
24
|
|
25
25
|
# create an ActiveRecord::Schema
|
26
26
|
if params['a']
|
@@ -43,10 +43,10 @@ else
|
|
43
43
|
puts "Records: #{table.record_count}"
|
44
44
|
|
45
45
|
puts "\nFields:"
|
46
|
-
puts
|
47
|
-
puts
|
46
|
+
puts 'Name Type Length Decimal'
|
47
|
+
puts '-' * 78
|
48
48
|
table.columns.each do |f|
|
49
|
-
puts
|
49
|
+
puts '%-16s %-10s %-10s %-10s' % [f.name, f.type, f.length, f.decimal]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
data/lib/dbf/column.rb
CHANGED
@@ -21,6 +21,7 @@ module DBF
|
|
21
21
|
G: ColumnType::General
|
22
22
|
}
|
23
23
|
TYPE_CAST_CLASS.default = ColumnType::String
|
24
|
+
TYPE_CAST_CLASS.freeze
|
24
25
|
|
25
26
|
# Initialize a new DBF::Column
|
26
27
|
#
|
@@ -81,68 +82,41 @@ module DBF
|
|
81
82
|
|
82
83
|
private
|
83
84
|
|
84
|
-
def clean(value) # nodoc
|
85
|
+
def clean(value) # :nodoc:
|
85
86
|
truncated_value = value.strip.partition("\x00").first
|
86
87
|
truncated_value.gsub(/[^\x20-\x7E]/, '')
|
87
88
|
end
|
88
89
|
|
89
|
-
def encode(value, strip_output = false) # nodoc
|
90
|
-
return value
|
90
|
+
def encode(value, strip_output = false) # :nodoc:
|
91
|
+
return value unless value.respond_to?(:encoding)
|
91
92
|
|
92
93
|
output = @encoding ? encode_string(value) : value
|
93
94
|
strip_output ? output.strip : output
|
94
95
|
end
|
95
96
|
|
96
|
-
def encoding_args # nodoc
|
97
|
+
def encoding_args # :nodoc:
|
97
98
|
@encoding_args ||= [
|
98
99
|
Encoding.default_external,
|
99
100
|
{undef: :replace, invalid: :replace}
|
100
101
|
]
|
101
102
|
end
|
102
103
|
|
103
|
-
def encode_string(string) # nodoc
|
104
|
+
def encode_string(string) # :nodoc:
|
104
105
|
string.force_encoding(@encoding).encode(*encoding_args)
|
105
106
|
end
|
106
107
|
|
107
|
-
def
|
108
|
-
case type
|
109
|
-
when 'N', 'F'
|
110
|
-
decimal > 0 ? ':float' : ':integer'
|
111
|
-
when 'I'
|
112
|
-
':integer'
|
113
|
-
when 'Y'
|
114
|
-
':decimal, :precision => 15, :scale => 4'
|
115
|
-
when 'D'
|
116
|
-
':date'
|
117
|
-
when 'T'
|
118
|
-
':datetime'
|
119
|
-
when 'L'
|
120
|
-
':boolean'
|
121
|
-
when 'M'
|
122
|
-
':text'
|
123
|
-
when 'B'
|
124
|
-
':binary'
|
125
|
-
else
|
126
|
-
if format == :sequel
|
127
|
-
":varchar, :size => #{length}"
|
128
|
-
else
|
129
|
-
":string, :limit => #{length}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def type_cast_class # nodoc
|
108
|
+
def type_cast_class # :nodoc:
|
135
109
|
@type_cast_class ||= begin
|
136
110
|
klass = @length == 0 ? ColumnType::Nil : TYPE_CAST_CLASS[type.to_sym]
|
137
111
|
klass.new(@decimal, @encoding)
|
138
112
|
end
|
139
113
|
end
|
140
114
|
|
141
|
-
def validate_length # nodoc
|
115
|
+
def validate_length # :nodoc:
|
142
116
|
raise LengthError, 'field length must be 0 or greater' if length < 0
|
143
117
|
end
|
144
118
|
|
145
|
-
def validate_name # nodoc
|
119
|
+
def validate_name # :nodoc:
|
146
120
|
raise NameError, 'column name cannot be empty' if @name.empty?
|
147
121
|
end
|
148
122
|
end
|
data/lib/dbf/column_type.rb
CHANGED
data/lib/dbf/database/foxpro.rb
CHANGED
@@ -21,7 +21,6 @@ module DBF
|
|
21
21
|
@dirname = File.dirname(@path)
|
22
22
|
@db = DBF::Table.new(@path)
|
23
23
|
@tables = extract_dbc_data
|
24
|
-
|
25
24
|
rescue Errno::ENOENT
|
26
25
|
raise DBF::FileNotFoundError, "file not found: #{data}"
|
27
26
|
end
|
@@ -33,7 +32,7 @@ module DBF
|
|
33
32
|
# Returns table with given name
|
34
33
|
# @return Table
|
35
34
|
def table(name)
|
36
|
-
Table.new(
|
35
|
+
Table.new table_path(name) do |table|
|
37
36
|
table.long_names = @tables[name]
|
38
37
|
end
|
39
38
|
end
|
@@ -53,12 +52,12 @@ module DBF
|
|
53
52
|
path
|
54
53
|
end
|
55
54
|
|
56
|
-
def method_missing(method, *args) # nodoc
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
def method_missing(method, *args) # :nodoc:
|
56
|
+
table_names.index(method.to_s) ? table(method.to_s) : super
|
57
|
+
end
|
58
|
+
|
59
|
+
def respond_to_missing?(method, *)
|
60
|
+
table_names.index(method.to_s) || super
|
62
61
|
end
|
63
62
|
|
64
63
|
private
|
@@ -67,7 +66,7 @@ module DBF
|
|
67
66
|
# just an ordinary table with a treelike structure. Field definitions
|
68
67
|
# are in the same order as in the linked tables but only the long name
|
69
68
|
# is provided.
|
70
|
-
def extract_dbc_data # nodoc
|
69
|
+
def extract_dbc_data # :nodoc:
|
71
70
|
data = {}
|
72
71
|
@db.each do |record|
|
73
72
|
next unless record
|
@@ -110,7 +109,7 @@ module DBF
|
|
110
109
|
class Table < DBF::Table
|
111
110
|
attr_accessor :long_names
|
112
111
|
|
113
|
-
def build_columns # nodoc
|
112
|
+
def build_columns # :nodoc:
|
114
113
|
columns = super
|
115
114
|
|
116
115
|
# modify the column definitions to use the long names as the
|
data/lib/dbf/encodings.rb
CHANGED
data/lib/dbf/memo/base.rb
CHANGED
@@ -28,19 +28,19 @@ module DBF
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def offset(start_block) # nodoc
|
31
|
+
def offset(start_block) # :nodoc:
|
32
32
|
start_block * block_size
|
33
33
|
end
|
34
34
|
|
35
|
-
def content_size(memo_size) # nodoc
|
35
|
+
def content_size(memo_size) # :nodoc:
|
36
36
|
(memo_size - block_size) + BLOCK_HEADER_SIZE
|
37
37
|
end
|
38
38
|
|
39
|
-
def block_content_size # nodoc
|
39
|
+
def block_content_size # :nodoc:
|
40
40
|
@block_content_size ||= block_size - BLOCK_HEADER_SIZE
|
41
41
|
end
|
42
42
|
|
43
|
-
def block_size #nodoc
|
43
|
+
def block_size # :nodoc:
|
44
44
|
BLOCK_SIZE
|
45
45
|
end
|
46
46
|
end
|