Module: Micdrop::Ext::Microfocus

Defined in:
lib/micdrop/ext/microfocus.rb

Overview

A simple parser to extract data from a "Micro Focus File with Header (DAT)" file.

Based on this spec: https://www.microfocus.com/documentation/server-express/sx20books/fhfile.htm

This format comes from old COBOL programs, and each file is conceptually similar to an SQL database table. Unlike SQL though, these DAT files lack type information; each row is raw binary and must be unpacked.

This does not implement the full spec, and is not well tested, but "works on my machine".

Defined Under Namespace

Modules: RecordOrganization, RecordType Classes: MicroFocusReader, Record

Class Method Summary collapse

Class Method Details

.read_microfocus_file(filename, unpack_spec: nil, unpack_mapping: nil) ⇒ Object

This is the main entrypoint to read a file, and its output is usable as a source.

unpack_spec is an optional spec, as would be passed to String#unpack, to extract the individual columns from the record. You may also provice an unpack_mapping which maps more human-readable columns names to column indexes.



198
199
200
201
202
203
# File 'lib/micdrop/ext/microfocus.rb', line 198

def self.read_microfocus_file(filename, unpack_spec: nil, unpack_mapping: nil)
  File.open filename, "rb" do |file|
    reader = MicroFocusReader.new file, unpack_spec: unpack_spec, unpack_mapping: unpack_mapping
    reader.each.entries
  end
end