File: header.rb

package info (click to toggle)
ruby-dbf 4.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,732 kB
  • sloc: ruby: 1,692; makefile: 9
file content (23 lines) | stat: -rw-r--r-- 581 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module DBF
  class Header
    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.unpack1('H2')

      case @version
      when '02'
        @record_count, @record_length = @data.unpack('x v x3 v')
        @header_length = 521
      else
        @record_count, @header_length, @record_length, @encoding_key = @data.unpack('x x3 V v2 x17 H2')
        @encoding = DBF::ENCODINGS[@encoding_key]
      end
    end
  end
end