lib/dbf/table.rb in dbf-1.7.1 vs lib/dbf/table.rb in dbf-1.7.2

- old
+ new

@@ -197,38 +197,54 @@ end def supports_encoding? "".respond_to? :encoding end + + def foxpro? + FOXPRO_VERSIONS.keys.include? @version + end private def column_class #nodoc - @column_class ||= if FOXPRO_VERSIONS.keys.include?(version) - FoxproColumn - else - Column + @column_class ||= if foxpro? + Column::Foxpro + else + Column::Dbase end end + def memo_class #nodoc + @memo_class ||= if foxpro? + Memo::Foxpro + else + if @version == "83" + Memo::Dbase3 + else + Memo::Dbase4 + end + end + end + def column_count #nodoc - @column_count ||= (@header_length - DBF_HEADER_SIZE + 1) / DBF_HEADER_SIZE + @column_count ||= ((@header_length - DBF_HEADER_SIZE + 1) / DBF_HEADER_SIZE).to_i end - def open_data(data) + def open_data(data) #nodoc data.is_a?(StringIO) ? data : File.open(data, 'rb') end def open_memo(data, memo = nil) #nodoc if memo.is_a? StringIO - DBF::Memo.new(memo, version) + memo_class.new(memo, version) elsif memo - DBF::Memo.open(memo, version) + memo_class.open(memo, version) elsif !data.is_a? StringIO dirname = File.dirname(data) basename = File.basename(data, '.*') files = Dir.glob("#{dirname}/#{basename}*.{fpt,FPT,dbt,DBT}") - files.any? ? DBF::Memo.open(files.first, version) : nil + files.any? ? memo_class.open(files.first, version) : nil else nil end end