Class: DBF::VersionConfig
- Inherits:
-
Object
- Object
- DBF::VersionConfig
- Defined in:
- lib/dbf/version_config.rb
Constant Summary collapse
- DBASE2_HEADER_SIZE =
8- DBASE3_HEADER_SIZE =
32- DBASE7_HEADER_SIZE =
68- VERSIONS =
{ '02' => 'FoxBase', '03' => 'dBase III without memo file', '04' => 'dBase IV without memo file', '05' => 'dBase V without memo file', '07' => 'Visual Objects 1.x', '30' => 'Visual FoxPro', '32' => 'Visual FoxPro with field type Varchar or Varbinary', '31' => 'Visual FoxPro with AutoIncrement field', '43' => 'dBASE IV SQL table files, no memo', '63' => 'dBASE IV SQL system files, no memo', '7b' => 'dBase IV with memo file', '83' => 'dBase III with memo file', '87' => 'Visual Objects 1.x with memo file', '8b' => 'dBase IV with memo file', '8c' => 'dBase 7', '8e' => 'dBase IV with SQL table', 'cb' => 'dBASE IV SQL table files, with memo', 'f5' => 'FoxPro with memo file', 'fb' => 'FoxPro without memo file' }.freeze
- FOXPRO_VERSIONS =
{ '30' => 'Visual FoxPro', '31' => 'Visual FoxPro with AutoIncrement field', 'f5' => 'FoxPro with memo file', 'fb' => 'FoxPro without memo file' }.freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#column_layout ⇒ Object
:nodoc:.
- #foxpro? ⇒ Boolean
- #header_size ⇒ Object
-
#initialize(version) ⇒ VersionConfig
constructor
A new instance of VersionConfig.
- #memo_class ⇒ Object
-
#read_column_args(table, io) ⇒ Object
Returns the Column.new arguments for the next column descriptor, or nil when the file ends mid-descriptor.
- #version_description ⇒ Object
Constructor Details
#initialize(version) ⇒ VersionConfig
Returns a new instance of VersionConfig.
40 41 42 |
# File 'lib/dbf/version_config.rb', line 40 def initialize(version) @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
38 39 40 |
# File 'lib/dbf/version_config.rb', line 38 def version @version end |
Instance Method Details
#column_layout ⇒ Object
:nodoc:
82 83 84 85 86 87 88 |
# File 'lib/dbf/version_config.rb', line 82 def column_layout # :nodoc: case version when '02' then [header_size * 2, 'A11 a C', [0]] when '04', '8c' then [48, 'A32 a C C x13', []] else [header_size, 'A11 a x4 C2', []] end end |
#foxpro? ⇒ Boolean
59 60 61 |
# File 'lib/dbf/version_config.rb', line 59 def foxpro? FOXPRO_VERSIONS.key?(version) end |
#header_size ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dbf/version_config.rb', line 48 def header_size case version when '02' DBASE2_HEADER_SIZE when '04', '8c' DBASE7_HEADER_SIZE else DBASE3_HEADER_SIZE end end |
#memo_class ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/dbf/version_config.rb', line 63 def memo_class if foxpro? Memo::Foxpro else version == '83' ? Memo::Dbase3 : Memo::Dbase4 end end |
#read_column_args(table, io) ⇒ Object
Returns the Column.new arguments for the next column descriptor, or nil when the file ends mid-descriptor. Unpacking a short descriptor would otherwise raise ArgumentError ("x outside of string").
74 75 76 77 78 79 80 |
# File 'lib/dbf/version_config.rb', line 74 def read_column_args(table, io) size, format, defaults = column_layout data = io.read(size) return nil unless data && data.bytesize == size [table, *data.unpack(format), *defaults] end |
#version_description ⇒ Object
44 45 46 |
# File 'lib/dbf/version_config.rb', line 44 def version_description VERSIONS[version] end |