dbf 4.1.6 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +172 -108
  3. data/Gemfile.lock +41 -40
  4. data/README.md +1 -1
  5. data/Rakefile +1 -1
  6. data/ci_A.dbf +0 -0
  7. data/lib/dbf/column.rb +3 -3
  8. data/lib/dbf/column_type.rb +9 -12
  9. data/lib/dbf/record.rb +4 -4
  10. data/lib/dbf/table.rb +16 -8
  11. data/lib/dbf/version.rb +1 -1
  12. data/nBOOKS.DBF +0 -0
  13. data/spec/dbf/column_spec.rb +3 -3
  14. data/spec/dbf/file_formats_spec.rb +18 -0
  15. data/spec/fixtures/dbase_02_summary.txt +23 -0
  16. data/spec/fixtures/dbase_32_summary.txt +11 -0
  17. data/spec/fixtures/dbase_8c.dbf +0 -0
  18. metadata +8 -51
  19. data/Gemfile.travis +0 -8
  20. data/docs/CNAME +0 -1
  21. data/docs/DBF/Column/LengthError.html +0 -124
  22. data/docs/DBF/Column/NameError.html +0 -124
  23. data/docs/DBF/Column.html +0 -947
  24. data/docs/DBF/ColumnType/Base.html +0 -389
  25. data/docs/DBF/ColumnType/Boolean.html +0 -238
  26. data/docs/DBF/ColumnType/Currency.html +0 -238
  27. data/docs/DBF/ColumnType/Date.html +0 -242
  28. data/docs/DBF/ColumnType/DateTime.html +0 -246
  29. data/docs/DBF/ColumnType/Double.html +0 -238
  30. data/docs/DBF/ColumnType/Float.html +0 -238
  31. data/docs/DBF/ColumnType/General.html +0 -238
  32. data/docs/DBF/ColumnType/Memo.html +0 -246
  33. data/docs/DBF/ColumnType/Nil.html +0 -238
  34. data/docs/DBF/ColumnType/Number.html +0 -242
  35. data/docs/DBF/ColumnType/SignedLong.html +0 -238
  36. data/docs/DBF/ColumnType/String.html +0 -240
  37. data/docs/DBF/ColumnType.html +0 -115
  38. data/docs/DBF/Database/Foxpro.html +0 -653
  39. data/docs/DBF/Database/Table.html +0 -346
  40. data/docs/DBF/Database.html +0 -126
  41. data/docs/DBF/FileNotFoundError.html +0 -124
  42. data/docs/DBF/Header.html +0 -723
  43. data/docs/DBF/Memo/Base.html +0 -485
  44. data/docs/DBF/Memo/Dbase3.html +0 -242
  45. data/docs/DBF/Memo/Dbase4.html +0 -230
  46. data/docs/DBF/Memo/Foxpro.html +0 -268
  47. data/docs/DBF/Memo.html +0 -117
  48. data/docs/DBF/NoColumnsDefined.html +0 -124
  49. data/docs/DBF/Record.html +0 -773
  50. data/docs/DBF/Schema.html +0 -980
  51. data/docs/DBF/Table.html +0 -1571
  52. data/docs/DBF.html +0 -200
  53. data/docs/_index.html +0 -415
  54. data/docs/class_list.html +0 -51
  55. data/docs/css/common.css +0 -1
  56. data/docs/css/full_list.css +0 -58
  57. data/docs/css/style.css +0 -497
  58. data/docs/file.README.html +0 -359
  59. data/docs/file_list.html +0 -56
  60. data/docs/frames.html +0 -17
  61. data/docs/index.html +0 -359
  62. data/docs/js/app.js +0 -314
  63. data/docs/js/full_list.js +0 -216
  64. data/docs/js/jquery.js +0 -4
  65. data/docs/method_list.html +0 -675
  66. data/docs/top-level-namespace.html +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a45d2baaa7a531875b0528d1d7b83f7cc01cfe502b85c42b461b5749745638a
4
- data.tar.gz: f5eebeb1bc1f3d49bab802671f7ac3cfbc7722a1c1a797173cfdd025a684e30f
3
+ metadata.gz: 429e8806f5675886a27b904b879c244f9808c83c3da82937d6953d13a01dd333
4
+ data.tar.gz: e3d916d24891b6f26237c41fc6cad865544b2c1b6c91430f93fad58a8d712298
5
5
  SHA512:
6
- metadata.gz: a9624d7a37d29bc6f2eaf3546ad41ec8e04b84d1c48ccc9d92122e9682161bbe706459468f6a220e288ba07203fb419574723b376236868f8351e6a66dc58b67
7
- data.tar.gz: d821ec9443f26d3c7c5515cd6f0722f0c5ebcdf189aee5689cb63133c1ba3d1d03a03b6c9f2f9f1514900169ce8895c7ca33cbc8e24611ddbfeb9c216ee5171b
6
+ metadata.gz: 542522a8b7964b4a517bb4a1c68ae95ebbebab15ca4ef9ca8b6ce515b5a4df73e8c8b6dd27bf7c9273d6c879839c165ed94bfc17a2a26b069697b6badcbac3f9
7
+ data.tar.gz: 81b8db3ad10edbef672257239b2c9389f7292420feb7fab8343c9e2736bbc17835a55101c87dae84463b0c931fcc6d5acb6a9a27190a37dd284d1e2175d4a5f0
data/CHANGELOG.md CHANGED
@@ -1,159 +1,223 @@
1
- # 4.1.5
2
- - Better handling for PIPE errors when using command line utility
1
+ # Changelog
3
2
 
4
- # 4.1.4
5
- - Add full support for FoxBase files
3
+ ## 4.2.2
6
4
 
7
- # 4.1.3
8
- - Raise DBF::NoColumnsDefined error when attempting to read records if no columns are defined
5
+ - Faster CSV generation
9
6
 
10
- # 4.1.1
11
- - Add required_ruby_version to gemspec
7
+ ## 4.2.1
12
8
 
13
- # 4.1.0
14
- - Return Time instead of DateTime
9
+ - Support for dBase IV "04" type files
15
10
 
16
- # 4.0.0
17
- - Drop support for ruby-2.2 and earlier
11
+ ## 4.2.0
18
12
 
19
- # 3.1.3
20
- - Ensure malformed dates return nil
13
+ - Initial support for dBase 7 files
21
14
 
22
- # 3.1.2
23
- - Fix incorrect columns list when StringIO and encoding set
15
+ ## 4.1.6
24
16
 
25
- # 3.1.1
26
- - Use Date.strptime to parse date fields
17
+ - Add support for file type 32
27
18
 
28
- # 3.1.0
29
- - Use :binary for binary fields in ActiveRecord schemas
19
+ ## 4.1.5
30
20
 
31
- # 3.0.8
32
- - Fix uninitialized constant error under Rails 5
21
+ - Better handling for PIPE errors when using command line utility
33
22
 
34
- # 3.0.7
35
- - Ignore non-existent records if header record count is incorrect
23
+ ## 4.1.4
36
24
 
37
- # 3.0.6
38
- - This version has been yanked from rubygems due to errors
25
+ - Add full support for FoxBase files
39
26
 
40
- # 3.0.5
41
- - Override table name for schema output
27
+ ## 4.1.3
42
28
 
43
- # 3.0.4
44
- - Adds -v command-line option to print version
45
- - Adds -r command-line option to create Sequel migration
29
+ - Raise DBF::NoColumnsDefined error when attempting to read records if no columns are defined
46
30
 
47
- # 3.0.3
48
- - Uninitialized (N)umbers should return nil
31
+ ## 4.1.1
49
32
 
50
- # 3.0.2
51
- - Performance improvements for large files
33
+ - Add required_ruby_version to gemspec
52
34
 
53
- # 3.0.1
54
- - Support FoxPro (G) general field type
55
- - Fix ruby warnings
35
+ ## 4.1.0
56
36
 
57
- # 3.0.0
58
- - Requires Ruby version 2.0 and above
59
- - Support the (G) General Foxpro field type
37
+ - Return Time instead of DateTime
60
38
 
61
- # 2.0.13
62
- - Support 64-bit currency signed currency values
63
- (see https://github.com/infused/dbf/pull/71)
39
+ ## 4.0.0
64
40
 
65
- # 2.0.12
66
- - Parse (I) values as signed
67
- (see https://github.com/infused/dbf/pull/70)
41
+ - Drop support for ruby-2.2 and earlier
68
42
 
69
- # 2.0.11
70
- - Foxpro doubles should always return the full stored precision
71
- (see https://github.com/infused/dbf/pull/69)
43
+ ## 3.1.3
72
44
 
73
- # 2.0.10
74
- - allow 0 length fields, but always return nil as value
45
+ - Ensure malformed dates return nil
75
46
 
76
- # 2.0.9
77
- - fix dBase IV attributes when memo file is missing
47
+ ## 3.1.2
78
48
 
79
- # 2.0.8
80
- - fix FoxPro currency fields on some builds of Ruby 1.9.3 and 2.0.0
49
+ - Fix incorrect columns list when StringIO and encoding set
81
50
 
82
- # 2.0.7
83
- - fix the dbf binary on some linux systems
51
+ ## 3.1.1
84
52
 
85
- # 2.0.6
86
- - build_memo returns nil on errors
53
+ - Use Date.strptime to parse date fields
87
54
 
88
- # 2.0.5
89
- - use correct FoxPro memo block size
55
+ ## 3.1.0
90
56
 
91
- # 2.0.4
92
- - memo fields return nil if memo file is missing
57
+ - Use :binary for binary fields in ActiveRecord schemas
93
58
 
94
- # 2.0.3
95
- - set encoding if table encoding is nil
59
+ ## 3.0.8
96
60
 
97
- # 2.0.2
98
- - Allow overriding the character encoding specified in the file
61
+ - Fix uninitialized constant error under Rails 5
99
62
 
100
- # 2.0.1
101
- - Add experimental support for character encodings under Ruby 1.8
63
+ ## 3.0.7
102
64
 
103
- # 2.0.0
104
- - #44 Require FasterCSV gem on all platforms
105
- - Remove rdoc development dependency
106
- - #42 Fixes encoding of memos
107
- - #43 Improve handling of record attributes
65
+ - Ignore non-existent records if header record count is incorrect
108
66
 
109
- # 1.7.5
110
- - fixes FoxPro currency (Y) fields
67
+ ## 3.0.6
111
68
 
112
- # 1.7.4
113
- - Replace Memo Type with Memo File boolean in command-line utility summary output
69
+ - This version has been yanked from rubygems due to errors
114
70
 
115
- # 1.7.3
116
- - find_all/find_first should ignore deleted records
71
+ ## 3.0.5
117
72
 
118
- # 1.7.2
119
- - Fix integer division under Ruby 1.8 when requiring mathn
120
- standard library (see http://bugs.ruby-lang.org/issues/2121)
73
+ - Override table name for schema output
121
74
 
122
- # 1.7.1
123
- - Fix Table.FOXPRO_VERSIONS breakage on Ruby 1.8
75
+ ## 3.0.4
124
76
 
125
- # 1.7.0
126
- - allow DBF::Table to work with dbf data in memory
127
- - allow DBF::Table#to_csv to write to STDOUT
77
+ - Adds -v command-line option to print version
78
+ - Adds -r command-line option to create Sequel migration
128
79
 
129
- # 1.6.7
130
- - memo columns return nil when no memo file found
80
+ ## 3.0.3
131
81
 
132
- # 1.6.6
133
- - add binary data type support to ActiveRecord schema output
82
+ - Uninitialized (N)umbers should return nil
134
83
 
135
- # 1.6.5
136
- - support for visual foxpro double (b) data type
84
+ ## 3.0.2
85
+
86
+ - Performance improvements for large files
137
87
 
138
- # 1.6.3
139
- - Replace invalid chars with 'unicode replacement character' (U+FFFD)
88
+ ## 3.0.1
89
+
90
+ - Support FoxPro (G) general field type
91
+ - Fix ruby warnings
92
+
93
+ ## 3.0.0
94
+
95
+ - Requires Ruby version 2.0 and above
96
+ - Support the (G) General Foxpro field type
97
+
98
+ ## 2.0.13
99
+
100
+ - Support 64-bit currency signed currency values
101
+ (see https://github.com/infused/dbf/pull/71)
102
+
103
+ ## 2.0.12
104
+
105
+ - Parse (I) values as signed
106
+ (see https://github.com/infused/dbf/pull/70)
107
+
108
+ ## 2.0.11
109
+
110
+ - Foxpro doubles should always return the full stored precision
111
+ (see https://github.com/infused/dbf/pull/69)
112
+
113
+ ## 2.0.10
114
+
115
+ - allow 0 length fields, but always return nil as value
116
+
117
+ ## 2.0.9
118
+
119
+ - fix dBase IV attributes when memo file is missing
120
+
121
+ ## 2.0.8
122
+
123
+ - fix FoxPro currency fields on some builds of Ruby 1.9.3 and 2.0.0
124
+
125
+ ## 2.0.7
126
+
127
+ - fix the dbf binary on some linux systems
128
+
129
+ ## 2.0.6
130
+
131
+ - build_memo returns nil on errors
132
+
133
+ ## 2.0.5
134
+
135
+ - use correct FoxPro memo block size
136
+
137
+ ## 2.0.4
138
+
139
+ - memo fields return nil if memo file is missing
140
+
141
+ ## 2.0.3
142
+
143
+ - set encoding if table encoding is nil
144
+
145
+ ## 2.0.2
146
+
147
+ - Allow overriding the character encoding specified in the file
148
+
149
+ ## 2.0.1
150
+
151
+ - Add experimental support for character encodings under Ruby 1.8
152
+
153
+ ## 2.0.0
154
+
155
+ - #44 Require FasterCSV gem on all platforms
156
+ - Remove rdoc development dependency
157
+ - #42 Fixes encoding of memos
158
+ - #43 Improve handling of record attributes
159
+
160
+ ## 1.7.5
161
+
162
+ - fixes FoxPro currency (Y) fields
163
+
164
+ ## 1.7.4
165
+
166
+ - Replace Memo Type with Memo File boolean in command-line utility summary output
167
+
168
+ ## 1.7.3
169
+
170
+ - find_all/find_first should ignore deleted records
171
+
172
+ ## 1.7.2
173
+
174
+ - Fix integer division under Ruby 1.8 when requiring mathn
175
+ standard library (see http://bugs.ruby-lang.org/issues/2121)
176
+
177
+ ## 1.7.1
178
+
179
+ - Fix Table.FOXPRO_VERSIONS breakage on Ruby 1.8
180
+
181
+ ## 1.7.0
182
+
183
+ - allow DBF::Table to work with dbf data in memory
184
+ - allow DBF::Table#to_csv to write to STDOUT
185
+
186
+ ## 1.6.7
187
+
188
+ - memo columns return nil when no memo file found
189
+
190
+ ## 1.6.6
191
+
192
+ - add binary data type support to ActiveRecord schema output
193
+
194
+ ## 1.6.5
195
+
196
+ - support for visual foxpro double (b) data type
197
+
198
+ ## 1.6.3
199
+
200
+ - Replace invalid chars with 'unicode replacement character' (U+FFFD)
140
201
 
141
202
  ## 1.6.2
142
- - add Table#filename method
143
- - Rakefile now loads gems with bundler
144
- - add Table#supports_encoding?
145
- - simplify encodings.yml loader
146
- - add rake and rdoc as development dependencies
147
- - simplify open_memo file search logic
148
- - remove unnecessary requires in spec helper
149
- - fix cli summary
203
+
204
+ - add Table#filename method
205
+ - Rakefile now loads gems with bundler
206
+ - add Table#supports_encoding?
207
+ - simplify encodings.yml loader
208
+ - add rake and rdoc as development dependencies
209
+ - simplify open_memo file search logic
210
+ - remove unnecessary requires in spec helper
211
+ - fix cli summary
150
212
 
151
213
  ## 1.6.1
152
- - fix YAML issue when using MRI version > 1.9.1
153
- - remove Table#seek_to_index and Table#current_record private methods
214
+
215
+ - fix YAML issue when using MRI version > 1.9.1
216
+ - remove Table#seek_to_index and Table#current_record private methods
154
217
 
155
218
  ## 1.6.0
156
- - remove activesupport gem dependency
219
+
220
+ - remove activesupport gem dependency
157
221
 
158
222
  ## 1.5.0
159
223
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (4.1.5)
4
+ dbf (4.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,10 +10,10 @@ GEM
10
10
  awesome_print (1.9.2)
11
11
  byebug (11.1.3)
12
12
  coderay (1.1.3)
13
- diff-lcs (1.4.4)
13
+ diff-lcs (1.5.0)
14
14
  e2mmap (0.1.0)
15
- ffi (1.15.3)
16
- formatador (0.3.0)
15
+ ffi (1.15.5)
16
+ formatador (1.1.0)
17
17
  guard (2.18.0)
18
18
  formatador (>= 0.2.4)
19
19
  listen (>= 2.7, < 4.0)
@@ -28,10 +28,10 @@ GEM
28
28
  guard (~> 2.1)
29
29
  guard-compat (~> 1.1)
30
30
  rspec (>= 2.99.0, < 4.0)
31
- io-console (0.5.9)
32
- irb (1.3.6)
33
- reline (>= 0.2.5)
34
- listen (3.6.0)
31
+ io-console (0.5.11)
32
+ irb (1.4.1)
33
+ reline (>= 0.3.0)
34
+ listen (3.7.1)
35
35
  rb-fsevent (~> 0.10, >= 0.10.3)
36
36
  rb-inotify (~> 0.9, >= 0.9.10)
37
37
  lumberjack (1.2.8)
@@ -40,59 +40,60 @@ GEM
40
40
  notiffany (0.1.3)
41
41
  nenv (~> 0.1)
42
42
  shellany (~> 0.0)
43
- parallel (1.20.1)
44
- parser (3.0.2.0)
43
+ parallel (1.22.1)
44
+ parser (3.1.2.0)
45
45
  ast (~> 2.4.1)
46
46
  pry (0.14.1)
47
47
  coderay (~> 1.1)
48
48
  method_source (~> 1.0)
49
- rainbow (3.0.0)
49
+ rainbow (3.1.1)
50
50
  rake (13.0.6)
51
- rb-fsevent (0.11.0)
51
+ rb-fsevent (0.11.1)
52
52
  rb-inotify (0.10.1)
53
53
  ffi (~> 1.0)
54
- regexp_parser (2.1.1)
55
- reline (0.2.6)
54
+ regexp_parser (2.5.0)
55
+ reline (0.3.1)
56
56
  io-console (~> 0.5)
57
57
  rexml (3.2.5)
58
- rspec (3.10.0)
59
- rspec-core (~> 3.10.0)
60
- rspec-expectations (~> 3.10.0)
61
- rspec-mocks (~> 3.10.0)
62
- rspec-core (3.10.1)
63
- rspec-support (~> 3.10.0)
64
- rspec-expectations (3.10.1)
58
+ rspec (3.11.0)
59
+ rspec-core (~> 3.11.0)
60
+ rspec-expectations (~> 3.11.0)
61
+ rspec-mocks (~> 3.11.0)
62
+ rspec-core (3.11.0)
63
+ rspec-support (~> 3.11.0)
64
+ rspec-expectations (3.11.0)
65
65
  diff-lcs (>= 1.2.0, < 2.0)
66
- rspec-support (~> 3.10.0)
67
- rspec-mocks (3.10.2)
66
+ rspec-support (~> 3.11.0)
67
+ rspec-mocks (3.11.1)
68
68
  diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.10.0)
70
- rspec-support (3.10.2)
71
- rubocop (1.18.4)
69
+ rspec-support (~> 3.11.0)
70
+ rspec-support (3.11.0)
71
+ rubocop (1.30.1)
72
72
  parallel (~> 1.10)
73
- parser (>= 3.0.0.0)
73
+ parser (>= 3.1.0.0)
74
74
  rainbow (>= 2.2.2, < 4.0)
75
75
  regexp_parser (>= 1.8, < 3.0)
76
- rexml
77
- rubocop-ast (>= 1.8.0, < 2.0)
76
+ rexml (>= 3.2.5, < 4.0)
77
+ rubocop-ast (>= 1.18.0, < 2.0)
78
78
  ruby-progressbar (~> 1.7)
79
79
  unicode-display_width (>= 1.4.0, < 3.0)
80
- rubocop-ast (1.9.0)
81
- parser (>= 3.0.1.1)
82
- rubocop-performance (1.11.4)
80
+ rubocop-ast (1.18.0)
81
+ parser (>= 3.1.1.0)
82
+ rubocop-performance (1.14.2)
83
83
  rubocop (>= 1.7.0, < 2.0)
84
84
  rubocop-ast (>= 0.4.0)
85
- rubocop-rspec (2.4.0)
86
- rubocop (~> 1.0)
87
- rubocop-ast (>= 1.1.0)
85
+ rubocop-rspec (2.11.1)
86
+ rubocop (~> 1.19)
88
87
  ruby-progressbar (1.11.0)
89
88
  shellany (0.0.1)
90
- thor (1.1.0)
91
- unicode-display_width (2.0.0)
92
- yard (0.9.26)
89
+ thor (1.2.1)
90
+ unicode-display_width (2.1.0)
91
+ webrick (1.7.0)
92
+ yard (0.9.28)
93
+ webrick (~> 1.7.0)
93
94
 
94
95
  PLATFORMS
95
- ruby
96
+ arm64-darwin-21
96
97
 
97
98
  DEPENDENCIES
98
99
  awesome_print
@@ -110,4 +111,4 @@ DEPENDENCIES
110
111
  yard
111
112
 
112
113
  BUNDLED WITH
113
- 2.2.15
114
+ 2.3.20
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DBF
2
2
  [![Version](https://img.shields.io/gem/v/dbf.svg?style=flat)](https://rubygems.org/gems/dbf)
3
- [![Build Status](https://img.shields.io/travis/infused/dbf/master.svg?style=flat)](https://travis-ci.com/infused/dbf)
3
+ [![Build Status](https://github.com/infused/dbf/actions/workflows/build.yml/badge.svg)](https://github.com/infused/dbf/actions/workflows/build.yml)
4
4
  [![Code Quality](https://img.shields.io/codeclimate/maintainability/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)
5
5
  [![Code Coverage](https://img.shields.io/codeclimate/c/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)
6
6
  [![Total Downloads](https://img.shields.io/gem/dt/dbf.svg)](https://rubygems.org/gems/dbf/)
data/Rakefile CHANGED
@@ -14,5 +14,5 @@ task default: :spec
14
14
 
15
15
  desc 'Open an irb session preloaded with this library'
16
16
  task :console do
17
- sh 'irb -rubygems -I lib -r dbf.rb'
17
+ sh 'irb -r rubygems -I lib -r dbf.rb'
18
18
  end
data/ci_A.dbf ADDED
Binary file
data/lib/dbf/column.rb CHANGED
@@ -21,7 +21,8 @@ module DBF
21
21
  L: ColumnType::Boolean,
22
22
  M: ColumnType::Memo,
23
23
  B: ColumnType::Double,
24
- G: ColumnType::General
24
+ G: ColumnType::General,
25
+ '+'.to_sym => ColumnType::SignedLong2
25
26
  }
26
27
  TYPE_CAST_CLASS.default = ColumnType::String
27
28
  TYPE_CAST_CLASS.freeze
@@ -79,8 +80,7 @@ module DBF
79
80
  private
80
81
 
81
82
  def clean(value) # :nodoc:
82
- truncated_value = value.strip.partition("\x00").first
83
- truncated_value.gsub(/[^\x20-\x7E]/, '')
83
+ value.strip.gsub("\x00", '').gsub(/[^\x20-\x7E]/, '')
84
84
  end
85
85
 
86
86
  def encode(value, strip_output = false) # :nodoc:
@@ -12,7 +12,6 @@ module DBF
12
12
  end
13
13
 
14
14
  class Nil < Base
15
-
16
15
  # @param _value [String]
17
16
  def type_cast(_value)
18
17
  nil
@@ -20,7 +19,6 @@ module DBF
20
19
  end
21
20
 
22
21
  class Number < Base
23
-
24
22
  # @param value [String]
25
23
  def type_cast(value)
26
24
  return nil if value.strip.empty?
@@ -30,7 +28,6 @@ module DBF
30
28
  end
31
29
 
32
30
  class Currency < Base
33
-
34
31
  # @param value [String]
35
32
  def type_cast(value)
36
33
  (value.unpack1('q<') / 10_000.0).to_f
@@ -38,15 +35,22 @@ module DBF
38
35
  end
39
36
 
40
37
  class SignedLong < Base
41
-
42
38
  # @param value [String]
43
39
  def type_cast(value)
44
40
  value.unpack1('l<')
45
41
  end
46
42
  end
47
43
 
48
- class Float < Base
44
+ class SignedLong2 < Base
45
+ # @param value [String]
46
+ def type_cast(value)
47
+ s = value.unpack1('B*')
48
+ sign_multiplier = s[0] == '0' ? -1 : 1
49
+ s[1, 31].to_i(2) * sign_multiplier
50
+ end
51
+ end
49
52
 
53
+ class Float < Base
50
54
  # @param value [String]
51
55
  def type_cast(value)
52
56
  value.to_f
@@ -54,7 +58,6 @@ module DBF
54
58
  end
55
59
 
56
60
  class Double < Base
57
-
58
61
  # @param value [String]
59
62
  def type_cast(value)
60
63
  value.unpack1('E')
@@ -62,7 +65,6 @@ module DBF
62
65
  end
63
66
 
64
67
  class Boolean < Base
65
-
66
68
  # @param value [String]
67
69
  def type_cast(value)
68
70
  value.strip.match?(/^(y|t)$/i)
@@ -70,7 +72,6 @@ module DBF
70
72
  end
71
73
 
72
74
  class Date < Base
73
-
74
75
  # @param value [String]
75
76
  def type_cast(value)
76
77
  value.match?(/\d{8}/) && ::Date.strptime(value, '%Y%m%d')
@@ -80,7 +81,6 @@ module DBF
80
81
  end
81
82
 
82
83
  class DateTime < Base
83
-
84
84
  # @param value [String]
85
85
  def type_cast(value)
86
86
  days, msecs = value.unpack('l2')
@@ -92,7 +92,6 @@ module DBF
92
92
  end
93
93
 
94
94
  class Memo < Base
95
-
96
95
  # @param value [String]
97
96
  def type_cast(value)
98
97
  if encoding && !value.nil?
@@ -104,7 +103,6 @@ module DBF
104
103
  end
105
104
 
106
105
  class General < Base
107
-
108
106
  # @param value [String]
109
107
  def type_cast(value)
110
108
  value
@@ -112,7 +110,6 @@ module DBF
112
110
  end
113
111
 
114
112
  class String < Base
115
-
116
113
  # @param value [String]
117
114
  def type_cast(value)
118
115
  value = value.strip
data/lib/dbf/record.rb CHANGED
@@ -38,7 +38,7 @@ module DBF
38
38
  #
39
39
  # @return [Hash]
40
40
  def attributes
41
- @attributes ||= Hash[attribute_map]
41
+ @attributes ||= Hash[column_names.zip(to_a)]
42
42
  end
43
43
 
44
44
  # Do all search parameters match?
@@ -53,13 +53,13 @@ module DBF
53
53
  #
54
54
  # @return [Array]
55
55
  def to_a
56
- @columns.map { |column| attributes[column.name] }
56
+ @to_a ||= @columns.map { |column| init_attribute(column) }
57
57
  end
58
58
 
59
59
  private
60
60
 
61
- def attribute_map # :nodoc:
62
- @columns.map { |column| [column.name, init_attribute(column)] }
61
+ def column_names # :nodoc:
62
+ @column_names ||= @columns.map { |column| column.name }
63
63
  end
64
64
 
65
65
  def get_data(column) # :nodoc: