dbf 4.3.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b15db465fcb977bf3684285e38b07c4748bc9b8713274a80cc09a27fdefda8ca
4
- data.tar.gz: f3009c19a0c6fd3f7291486a72a32a97a1a9f29fe4f24cd34f4d6a8e171b9879
3
+ metadata.gz: 8d40b6c4a0c614eda7638ef810b682b3ee767153b95cc4075d90c1f12937e57c
4
+ data.tar.gz: 6b74646387585dc0d497181d2253324cf92717b217b6642f5a1e307a7413e557
5
5
  SHA512:
6
- metadata.gz: d99ab54892f6a2454a1c46191eea92c56d3efe4319e592cf767b53376b9c11c650d339aa6e0a88d4b959997a4f5beddcfd20f1dd9080ef60cef4ebf76bcd2214
7
- data.tar.gz: da0a365801ac686861e92c5f22bf6b5fe9b383c14b7f65db6a2dcb95d3ec00be680a2b44b959b040296ccf833b778d64dd6677c6717ae08450ec7e312bde2b02
6
+ metadata.gz: 98414f9a53a66b60f69b419740cb2f28eff4bdd81de67e5b09b9ae274c1f5a2e40c8730546f4719c09078b590837b1da607685833034f96a86ab2bea62637629
7
+ data.tar.gz: 28a3a92617d4d889777d718cd88f43cec0217c6fd64135375699f81047186ddad0d1a345f32e2822d8f29a192fec579bef255efd316c5fb10594740042cd63a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.1
4
+
5
+ - Fix bug (since 4.2.0) that caused column names not to be truncated after null character
6
+
3
7
  ## 4.3.0
4
8
 
5
9
  - Drop support for Ruby versions older than 3.0
data/README.md CHANGED
@@ -16,19 +16,19 @@ DBF is a small, fast Ruby library for reading dBase, xBase, Clipper, and FoxPro
16
16
  subject line
17
17
  * Change log: <https://github.com/infused/dbf/blob/master/CHANGELOG.md>
18
18
 
19
- NOTE:
19
+ NOTE: Beginning with version 4.3 we have dropped support for Ruby 3.0 and earlier.
20
20
 
21
- NOTE: Beginning with version 4, we have dropped support for Ruby 2.0, 2.1, 2.2, and 2.3. If you need support for these older Rubies,
21
+ NOTE: Beginning with version 4 we have dropped support for Ruby 2.0, 2.1, 2.2, and 2.3. If you need support for these older Rubies,
22
22
  please use 3.0.x (<https://github.com/infused.org/dbf/tree/3_stable>)
23
23
 
24
- NOTE: Beginning with version 3, we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies,
24
+ NOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies,
25
25
  please use 2.0.x (<https://github.com/infused/dbf/tree/2_stable>)
26
26
 
27
27
  ## Compatibility
28
28
 
29
29
  DBF is tested to work with the following versions of Ruby:
30
30
 
31
- * Ruby 3.0.x, 3.1.x, 3.2.x, 3.3.x
31
+ * Ruby 3.1.x, 3.2.x, 3.3.x
32
32
 
33
33
  ## Installation
34
34
 
data/lib/dbf/column.rb CHANGED
@@ -9,8 +9,10 @@ module DBF
9
9
  end
10
10
 
11
11
  attr_reader :table, :name, :type, :length, :decimal
12
+
12
13
  def_delegator :type_cast_class, :type_cast
13
14
 
15
+ # rubocop:disable Style/MutableConstant
14
16
  TYPE_CAST_CLASS = {
15
17
  N: ColumnType::Number,
16
18
  I: ColumnType::SignedLong,
@@ -24,6 +26,7 @@ module DBF
24
26
  G: ColumnType::General,
25
27
  '+'.to_sym => ColumnType::SignedLong2
26
28
  }
29
+ # rubocop:enable Style/MutableConstant
27
30
  TYPE_CAST_CLASS.default = ColumnType::String
28
31
  TYPE_CAST_CLASS.freeze
29
32
 
@@ -58,7 +61,7 @@ module DBF
58
61
  #
59
62
  # @return [Hash]
60
63
  def to_hash
61
- {name: name, type: type, length: length, decimal: decimal}
64
+ {name:, type:, length:, decimal:}
62
65
  end
63
66
 
64
67
  # Underscored name
@@ -68,18 +71,17 @@ module DBF
68
71
  #
69
72
  # @return [String]
70
73
  def underscored_name
71
- @underscored_name ||= begin
72
- name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
73
- end
74
+ @underscored_name ||= name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
75
+
74
76
  end
75
77
 
76
78
  private
77
79
 
78
80
  def clean(value) # :nodoc:
79
- value.strip.gsub("\x00", '').gsub(/[^\x20-\x7E]/, '')
81
+ value.strip.partition("\x00").first.gsub(/[^\x20-\x7E]/, '')
80
82
  end
81
83
 
82
- def encode(value, strip_output = false) # :nodoc:
84
+ def encode(value, strip_output: false) # :nodoc:
83
85
  return value unless value.respond_to?(:encoding)
84
86
 
85
87
  output = @encoding ? encode_string(value) : value
@@ -105,7 +105,7 @@ module DBF
105
105
  end
106
106
 
107
107
  def table_field_hash(name)
108
- {name: name, fields: []}
108
+ {name:, fields: []}
109
109
  end
110
110
  end
111
111
 
data/lib/dbf/header.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  module DBF
2
2
  class Header
3
- attr_reader :version
4
- attr_reader :record_count
5
- attr_reader :header_length
6
- attr_reader :record_length
7
- attr_reader :encoding_key
8
- attr_reader :encoding
3
+ attr_reader :version, :record_count, :header_length, :record_length, :encoding_key, :encoding
9
4
 
10
5
  def initialize(data)
11
6
  @data = data
@@ -13,7 +8,7 @@ module DBF
13
8
  end
14
9
 
15
10
  def unpack_header
16
- @version = @data.unpack('H2').first
11
+ @version = @data.unpack1('H2')
17
12
 
18
13
  case @version
19
14
  when '02'
data/lib/dbf/record.rb CHANGED
@@ -29,7 +29,7 @@ module DBF
29
29
  key = name.to_s
30
30
  if attributes.key?(key)
31
31
  attributes[key]
32
- elsif index = underscored_column_names.index(key)
32
+ elsif (index = underscored_column_names.index(key))
33
33
  attributes[@columns[index].name]
34
34
  end
35
35
  end
@@ -59,7 +59,7 @@ module DBF
59
59
  private
60
60
 
61
61
  def column_names # :nodoc:
62
- @column_names ||= @columns.map { |column| column.name }
62
+ @column_names ||= @columns.map(&:name)
63
63
  end
64
64
 
65
65
  def get_data(column) # :nodoc:
data/lib/dbf/schema.rb CHANGED
@@ -35,9 +35,9 @@ module DBF
35
35
  # @param format [Symbol] format Valid options are :activerecord and :json
36
36
  # @param table_only [Boolean]
37
37
  # @return [String]
38
- def schema(format = :activerecord, table_only = false)
38
+ def schema(format = :activerecord, table_only: false)
39
39
  schema_method_name = schema_name(format)
40
- send(schema_method_name, table_only)
40
+ send(schema_method_name, table_only:)
41
41
  rescue NameError
42
42
  raise ArgumentError, ":#{format} is not a valid schema. Valid schemas are: #{FORMATS.join(', ')}."
43
43
  end
@@ -46,7 +46,7 @@ module DBF
46
46
  "#{format}_schema"
47
47
  end
48
48
 
49
- def activerecord_schema(_table_only = false) # :nodoc:
49
+ def activerecord_schema(*) # :nodoc:
50
50
  s = "ActiveRecord::Schema.define do\n"
51
51
  s << " create_table \"#{name}\" do |t|\n"
52
52
  columns.each do |column|
@@ -56,7 +56,7 @@ module DBF
56
56
  s
57
57
  end
58
58
 
59
- def sequel_schema(table_only = false) # :nodoc:
59
+ def sequel_schema(table_only: false) # :nodoc:
60
60
  s = ''
61
61
  s << "Sequel.migration do\n" unless table_only
62
62
  s << " change do\n " unless table_only
@@ -70,7 +70,7 @@ module DBF
70
70
  s
71
71
  end
72
72
 
73
- def json_schema(_table_only = false) # :nodoc:
73
+ def json_schema(*) # :nodoc:
74
74
  columns.map(&:to_hash).to_json
75
75
  end
76
76
 
@@ -92,9 +92,9 @@ module DBF
92
92
 
93
93
  def schema_data_type(column, format = :activerecord) # :nodoc:
94
94
  case column.type
95
- when *%w[N F I]
95
+ when 'N', 'F', 'I'
96
96
  number_data_type(column)
97
- when *%w[Y D T L M B]
97
+ when 'Y', 'D', 'T', 'L', 'M', 'B'
98
98
  OTHER_DATA_TYPES[column.type]
99
99
  else
100
100
  string_data_format(format, column)
data/lib/dbf/table.rb CHANGED
@@ -86,7 +86,7 @@ module DBF
86
86
  # @return [TrueClass, FalseClass]
87
87
  def close
88
88
  @data.close
89
- @memo && @memo.close
89
+ @memo&.close
90
90
  end
91
91
 
92
92
  # @return [TrueClass, FalseClass]
@@ -255,7 +255,7 @@ module DBF
255
255
 
256
256
  def find_all(options) # :nodoc:
257
257
  select do |record|
258
- next unless record && record.match?(options)
258
+ next unless record&.match?(options)
259
259
 
260
260
  yield record if block_given?
261
261
  record
@@ -263,7 +263,7 @@ module DBF
263
263
  end
264
264
 
265
265
  def find_first(options) # :nodoc:
266
- detect { |record| record && record.match?(options) }
266
+ detect { |record| record&.match?(options) }
267
267
  end
268
268
 
269
269
  def foxpro? # :nodoc:
@@ -278,13 +278,12 @@ module DBF
278
278
  end
279
279
 
280
280
  def memo_class # :nodoc:
281
- @memo_class ||= begin
282
- if foxpro?
283
- Memo::Foxpro
281
+ @memo_class ||= if foxpro?
282
+ Memo::Foxpro
284
283
  else
285
284
  version == '83' ? Memo::Dbase3 : Memo::Dbase4
286
- end
287
285
  end
286
+
288
287
  end
289
288
 
290
289
  def memo_search_path(io) # :nodoc:
data/lib/dbf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '4.3.0'.freeze
2
+ VERSION = '4.3.1'.freeze
3
3
  end
@@ -287,12 +287,12 @@ RSpec.describe DBF::Column do
287
287
  describe '#name' do
288
288
  it 'contains only ASCII characters' do
289
289
  column = DBF::Column.new table, "--\x1F-\x68\x65\x6C\x6C\x6F \x00world-\x80--", 'N', 1, 0
290
- expect(column.name).to eq '---hello world---'
290
+ expect(column.name).to eq '---hello '
291
291
  end
292
292
 
293
293
  it 'is truncated at the null character' do
294
294
  column = DBF::Column.new table, "--\x1F-\x68\x65\x6C\x6C\x6F \x00world-\x80\x80--", 'N', 1, 0
295
- expect(column.name).to eq '---hello world---'
295
+ expect(column.name).to eq '---hello '
296
296
  end
297
297
  end
298
298
  end
@@ -3,25 +3,25 @@ require 'spec_helper'
3
3
  RSpec.describe DBF::Record do
4
4
  describe '#to_a' do
5
5
  let(:table) { DBF::Table.new fixture('dbase_83.dbf') }
6
- let(:record_0) { YAML.load_file(fixture('dbase_83_record_0.yml')) }
7
- let(:record_9) { YAML.load_file(fixture('dbase_83_record_9.yml')) }
6
+ let(:record0) { YAML.load_file(fixture('dbase_83_record_0.yml')) }
7
+ let(:record9) { YAML.load_file(fixture('dbase_83_record_9.yml')) }
8
8
 
9
9
  it 'returns an ordered array of attribute values' do
10
10
  record = table.record(0)
11
- expect(record.to_a).to eq record_0
11
+ expect(record.to_a).to eq record0
12
12
 
13
13
  record = table.record(9)
14
- expect(record.to_a).to eq record_9
14
+ expect(record.to_a).to eq record9
15
15
  end
16
16
 
17
17
  describe 'with missing memo file' do
18
18
  describe 'when opening a path' do
19
19
  let(:table) { DBF::Table.new fixture('dbase_83_missing_memo.dbf') }
20
- let(:record_0) { YAML.load_file(fixture('dbase_83_missing_memo_record_0.yml')) }
20
+ let(:record0) { YAML.load_file(fixture('dbase_83_missing_memo_record_0.yml')) }
21
21
 
22
22
  it 'returns nil values for memo fields' do
23
23
  record = table.record(0)
24
- expect(record.to_a).to eq record_0
24
+ expect(record.to_a).to eq record0
25
25
  end
26
26
  end
27
27
  end
@@ -29,11 +29,11 @@ RSpec.describe DBF::Record do
29
29
  describe 'when opening StringIO' do
30
30
  let(:data) { StringIO.new(File.read(fixture('dbase_83_missing_memo.dbf'))) }
31
31
  let(:table) { DBF::Table.new(data) }
32
- let(:record_0) { YAML.load_file(fixture('dbase_83_missing_memo_record_0.yml')) }
32
+ let(:record0) { YAML.load_file(fixture('dbase_83_missing_memo_record_0.yml')) }
33
33
 
34
34
  it 'returns nil values for memo fields' do
35
35
  record = table.record(0)
36
- expect(record.to_a).to eq record_0
36
+ expect(record.to_a).to eq record0
37
37
  end
38
38
  end
39
39
  end
@@ -50,7 +50,7 @@ RSpec.describe DBF::Record do
50
50
 
51
51
  describe 'if other attributes match' do
52
52
  let(:attributes) { {x: 1, y: 2} }
53
- let(:other) { instance_double('DBF::Record', attributes: attributes) }
53
+ let(:other) { instance_double('DBF::Record', attributes:) }
54
54
 
55
55
  before do
56
56
  allow(record).to receive(:attributes).and_return(attributes)
@@ -70,7 +70,6 @@ RSpec.describe DBF::Table do
70
70
 
71
71
  describe 'when data is StringIO' do
72
72
  let(:data) { StringIO.new File.read(dbf_path) }
73
- let(:memo) { StringIO.new File.read(memo_path) }
74
73
  let(:table) { DBF::Table.new data }
75
74
 
76
75
  let(:control_schema) { File.read(fixture('dbase_83_schema_ar.txt')) }
@@ -200,7 +199,7 @@ RSpec.describe DBF::Table do
200
199
  end
201
200
 
202
201
  it 'returns matching records when used with options' do
203
- expect(table.find(:all, 'WEIGHT' => 0.0)).to eq table.select { |r| r['weight'] == 0.0 }
202
+ expect(table.find(:all, 'WEIGHT' => 0.0)).to eq(table.select { |r| r['weight'] == 0.0 })
204
203
  end
205
204
 
206
205
  it 'ANDS multiple search terms' do
@@ -295,7 +294,7 @@ RSpec.describe DBF::Table do
295
294
  it 'is an array of Columns' do
296
295
  expect(columns).to be_an(Array)
297
296
  expect(columns).to_not be_empty
298
- expect(columns).to be_all { |c| c.is_a? DBF::Column }
297
+ expect(columns).to(be_all { |c| c.is_a? DBF::Column })
299
298
  end
300
299
  end
301
300
 
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ begin
2
2
  require 'simplecov'
3
3
  SimpleCov.start
4
4
  rescue LoadError
5
+ # ignore
5
6
  end
6
7
 
7
8
  require 'dbf'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-27 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv