posexional v0.0.2 Posexional

Posexional is a library to manage positional files in elixir.

Positional files are the most bad and terrifying file format you ever want to work with, believe me, it’s utter crap. Still some web services use this format to expose data services, and if you are here reading this, probably you are in luck like us!

A positional file has a format specification like this:

field nameoffsetlengthnotes
code05request code fill with 0 and align on the right
prog05progressive number (fill with spaces)
type212AA
number24201
name2710person name (fill with -)
future use382leave empty
end411!

The expected results should be something like this:

000B1    1AA01george----  !
000B2    2AA01john------  !
000B3    3AA01ringo-----  !
000B4    4AA01paul------  !

cool uh?

With Posexional you can produce this file with

alias Posexional.Field

beatles_row = Posexional.Row.new(:beatles, [
  Field.Value.new(:code, 5, ?0, :right),
  Field.ProgressiveNumber.new(5),
  Field.Value.new(:type, 2),
  Field.Value.new(:number, 2),
  Field.Value.new(:name, 10, ?-),
  Field.Empty.new(2),
  Field.Value.new(:end, 1, ?!)
])

file = Posexional.File.new([beatles_row])

Posexional.write(file, [beatles: [
  code: "B1", type: "AA", number: "01", name: "george"
], beatles: [
  code: "B2", type: "AA", number: "01", name: "john"
], beatles: [
  code: "B2", type: "AA", number: "01", name: "ringo"
], beatles: [
  code: "B2", type: "AA", number: "01", name: "paul"
]])

In the first part we define the structure. We are not saying what the content or the number of rows there will be, we are just saying that there is a row called :beatles with the named field in it.

Then we create a Posexional.File struct and say that only the beatles row will be in there.

Then we can call Posexional.write/2, we pass the Posexional.File struct just defined and we feed the real data that should be written there. Just the relevant data, The empty fields or the progressive number is managed by the library itself.

And even better, with the Posexional.File struct that we defined, we can even read a positional file

Summary

Functions

read a positional stream of data with the given struct, returns a keyword list of the extracted data

same as read/2, but with a path to a file to read the stream from

write a positional file with the given stuct and data

same as write/2, but with a path to a new file to write the result to

Functions

read(positional_file, content)

Specs

read(%Posexional.File{rows: term, separator: term}, binary) :: Keyword.t

read a positional stream of data with the given struct, returns a keyword list of the extracted data

read_file!(file, path)

Specs

read_file!(%Posexional.File{rows: term, separator: term}, binary) :: Keyword.t

same as read/2, but with a path to a file to read the stream from

write(positional_file, values)

Specs

write(%Posexional.File{rows: term, separator: term}, Keyword.t) :: binary

write a positional file with the given stuct and data

write_file!(positional_file, values, path)

Specs

write_file!(%Posexional.File{rows: term, separator: term}, Keyword.t, binary) :: nil

same as write/2, but with a path to a new file to write the result to