Skip to content

Commit

Permalink
use ruby 3.x patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
infused committed Dec 27, 2023
1 parent 232015a commit 5212af4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ require:
- rubocop-rspec
- rubocop-performance

AllCops:
SuggestExtensions: true

Layout/CaseIndentation:
Enabled: false

Expand Down
10 changes: 5 additions & 5 deletions lib/dbf/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NameError < StandardError
end

attr_reader :table, :name, :type, :length, :decimal

def_delegator :type_cast_class, :type_cast

TYPE_CAST_CLASS = {
Expand Down Expand Up @@ -58,7 +59,7 @@ def memo?
#
# @return [Hash]
def to_hash
{name: name, type: type, length: length, decimal: decimal}
{name:, type:, length:, decimal:}
end

# Underscored name
Expand All @@ -68,15 +69,14 @@ def to_hash
#
# @return [String]
def underscored_name
@underscored_name ||= begin
name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
end
@underscored_name ||= name.gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase

end

private

def clean(value) # :nodoc:
value.strip.gsub("\x00", '').gsub(/[^\x20-\x7E]/, '')
value.strip.delete("\x00").gsub(/[^\x20-\x7E]/, '')
end

def encode(value, strip_output = false) # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion lib/dbf/database/foxpro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def process_field(record, data)
end

def table_field_hash(name)
{name: name, fields: []}
{name:, fields: []}
end
end

Expand Down
9 changes: 2 additions & 7 deletions lib/dbf/header.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
module DBF
class Header
attr_reader :version
attr_reader :record_count
attr_reader :header_length
attr_reader :record_length
attr_reader :encoding_key
attr_reader :encoding
attr_reader :version, :record_count, :header_length, :record_length, :encoding_key, :encoding

def initialize(data)
@data = data
unpack_header
end

def unpack_header
@version = @data.unpack('H2').first
@version = @data.unpack1('H2')

case @version
when '02'
Expand Down
7 changes: 3 additions & 4 deletions lib/dbf/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,12 @@ def header # :nodoc:
end

def memo_class # :nodoc:
@memo_class ||= begin
if foxpro?
Memo::Foxpro
@memo_class ||= if foxpro?
Memo::Foxpro
else
version == '83' ? Memo::Dbase3 : Memo::Dbase4
end
end

end

def memo_search_path(io) # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion spec/dbf/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

describe 'if other attributes match' do
let(:attributes) { {x: 1, y: 2} }
let(:other) { instance_double('DBF::Record', attributes: attributes) }
let(:other) { instance_double('DBF::Record', attributes:) }

before do
allow(record).to receive(:attributes).and_return(attributes)
Expand Down

0 comments on commit 5212af4

Please sign in to comment.