lib/dbf/table.rb in dbf-2.0.13 vs lib/dbf/table.rb in dbf-3.0.0

- old
+ new

@@ -36,11 +36,11 @@ 'f5' => 'FoxPro with memo file', 'fb' => 'FoxPro without memo file' } attr_reader :header - attr_accessor :encoding # Source encoding (for ex. :cp1251) + attr_accessor :encoding # Opens a DBF::Table # Examples: # # working with a file stored on the filesystem # table = DBF::Table.new 'data.dbf' @@ -146,11 +146,11 @@ # output to STDOUT. # # @param [optional String] path Defaults to STDOUT def to_csv(path = nil) out_io = path ? File.open(path, 'w') : $stdout - csv = csv_class.new(out_io, :force_quotes => true) + csv = CSV.new(out_io, force_quotes: true) csv << column_names each { |record| csv << record.to_a } end # Find records using a simple ActiveRecord-like syntax. @@ -225,25 +225,25 @@ end private def build_columns # nodoc - columns = [] @data.seek(DBF_HEADER_SIZE) - while !end_of_record? + 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) end columns end def end_of_record? # nodoc - pos = @data.pos + original_pos = @data.pos byte = @data.read(1) - @data.seek(pos) - byte[0].ord == 13 + @data.seek(original_pos) + byte.ord == 13 end def foxpro? # nodoc FOXPRO_VERSIONS.keys.include? version end @@ -251,14 +251,16 @@ def column_class # nodoc @column_class ||= foxpro? ? Column::Foxpro : Column::Dbase end def memo_class # nodoc - @memo_class ||= if foxpro? - Memo::Foxpro - else - version == '83' ? Memo::Dbase3 : Memo::Dbase4 + @memo_class ||= begin + if foxpro? + Memo::Foxpro + else + version == '83' ? Memo::Dbase3 : Memo::Dbase4 + end end end def open_data(data) # nodoc data.is_a?(StringIO) ? data : File.open(data, 'rb') @@ -301,12 +303,8 @@ @data.seek header.header_length + offset end def seek_to_record(index) # nodoc seek(index * header.record_length) - end - - def csv_class # nodoc - @csv_class ||= CSV.const_defined?(:Reader) ? FCSV : CSV end end end