lib/dbf/table.rb in dbf-3.0.0 vs lib/dbf/table.rb in dbf-3.0.1
- old
+ new
@@ -62,11 +62,11 @@
# @param [optional String, StringIO] memo Path to the memo file or a StringIO object
# @param [optional String, Encoding] encoding Name of the encoding or an Encoding object
def initialize(data, memo = nil, encoding = nil)
@data = open_data(data)
@data.rewind
- @header = Header.new(@data.read(DBF_HEADER_SIZE), supports_encoding?)
+ @header = Header.new(@data.read DBF_HEADER_SIZE)
@encoding = encoding || header.encoding
@memo = open_memo(data, memo)
yield self if block_given?
rescue Errno::ENOENT
raise DBF::FileNotFoundError, "file not found: #{data}"
@@ -160,14 +160,14 @@
#
# # Find record number 5
# table.find(5)
#
# # Find all records for Keith Morrison
- # table.find :all, :first_name => "Keith", :last_name => "Morrison"
+ # table.find :all, first_name: "Keith", last_name: "Morrison"
#
# # Find first record
- # table.find :first, :first_name => "Keith"
+ # table.find :first, first_name: "Keith"
#
# The <b>command</b> may be a record index, :all, or :first.
# <b>options</b> is optional and, if specified, should be a hash where the
# keys correspond to column names in the database. The values will be
# matched exactly with the value in the database. If you specify more
@@ -203,38 +203,19 @@
# @return [String]
def column_names
columns.map(&:name)
end
- # Is string encoding supported?
- # String encoding is always supported in Ruby 1.9+.
- # Ruby 1.8.x requires that Ruby be compiled with iconv support.
- def supports_encoding?
- supports_string_encoding? || supports_iconv?
- end
-
- # Does String support encoding? Should be true in Ruby 1.9+
- def supports_string_encoding?
- ''.respond_to?(:encoding)
- end
-
- def supports_iconv? # nodoc
- require 'iconv'
- true
- rescue
- false
- end
-
private
def build_columns # nodoc
@data.seek(DBF_HEADER_SIZE)
columns = []
until end_of_record?
column_data = @data.read(DBF_HEADER_SIZE)
name, type, length, decimal = column_data.unpack('a10 x a x4 C2')
- columns << column_class.new(self, name, type, length, decimal)
+ columns << Column.new(self, name, type, length, decimal)
end
columns
end
def end_of_record? # nodoc
@@ -244,13 +225,9 @@
byte.ord == 13
end
def foxpro? # nodoc
FOXPRO_VERSIONS.keys.include? version
- end
-
- def column_class # nodoc
- @column_class ||= foxpro? ? Column::Foxpro : Column::Dbase
end
def memo_class # nodoc
@memo_class ||= begin
if foxpro?