Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set encoding if table encoding is nil #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/dbf/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Table
"f5" => "FoxPro with memo file",
"fb" => "FoxPro without memo file"
}

FOXPRO_VERSIONS = {
"30" => "Visual FoxPro",
"31" => "Visual FoxPro with AutoIncrement field",
Expand Down Expand Up @@ -59,10 +59,10 @@ class Table
def initialize(data, memo = nil, encoding = nil)
@data = open_data(data)
get_header_info
@encoding = encoding if encoding && @encoding
@encoding = encoding || @encoding
@memo = open_memo(data, memo)
end

# @return [TrueClass, FalseClass]
def has_memo_file?
!!@memo
Expand All @@ -75,7 +75,7 @@ def close
@data.close
@memo && @memo.close
end

# @return [TrueClass, FalseClass]
def closed?
if @memo
Expand All @@ -84,7 +84,7 @@ def closed?
@data.closed?
end
end

# @return String
def filename
File.basename @data.path
Expand Down Expand Up @@ -213,32 +213,32 @@ def columns
columns
end
end

def supports_encoding?
String.new.respond_to?(:encoding)
end

def supports_iconv?
require 'iconv'
true
rescue
false
end

def foxpro?
FOXPRO_VERSIONS.keys.include? @version
end

private

def column_class #nodoc
@column_class ||= if foxpro?
Column::Foxpro
else
Column::Dbase
end
end

def memo_class #nodoc
@memo_class ||= if foxpro?
Memo::Foxpro
Expand All @@ -250,7 +250,7 @@ def memo_class #nodoc
end
end
end

def column_count #nodoc
@column_count ||= ((@header_length - DBF_HEADER_SIZE + 1) / DBF_HEADER_SIZE).to_i
end
Expand Down Expand Up @@ -296,7 +296,7 @@ def get_header_info #nodoc
@version, @record_count, @header_length, @record_length, @encoding_key = read_header
@encoding = ENCODINGS[@encoding_key] if supports_encoding? || supports_iconv?
end

def read_header #nodoc
@data.read(DBF_HEADER_SIZE).unpack("H2 x3 V v2 x17H2")
end
Expand Down