This is a gem for parsing DOST (Dynamic Offset Table) files.
It is prealpha version of package, please do not use it in production if you don't know what are you doing :)
This is a parser of DOST (Dynamic Offset Separated Table).
DOST - this is a simple format from .NET framework
Add this line to your application's Gemfile:
gem 'dost'And then execute:
$ bundle
Or install it yourself as:
$ gem install dost
=========================
FUU BAR SOMEVERYLONG
FIELD
-------------------------
11 22 200000000000
111 220 300000000000
=========================Let's assume that example.txt is a file with content from example above
lines = File.open('example.txt').read.lines.map(&:chomp)
dost_data = DOST::Data.new(
lines: lines,
headers_delimiters: ['=', '-'],
values_delimiters: ['-', '='],
key_modifier: ->(key) { key.strip.downcase.to_sym }
)
pry(main)> dost_data.headers
=> [[:fuu, 0..6], [:bar, 7..12], [:someverylong, 13..24]]
pry(main)> dost_data.values
=> [{:fuu=>"11", :bar=>"22", :someverylong=>"200000000000"}, {:fuu=>"111", :bar=>"220", :someverylong=>"300000000000"}]- lines - Lines from file, usually you can get it by
File.open('example.txt').read.lines.map(&:chomp) - headers_delimiters - Array of 2 chars, first define start of headers section, second one - end of header section (delimiter is a line that contain all same symbols except all whitespaces)
- values_delimiters - same as for header but for values
- key_modifier - proc that would be applied for your keys of headers. In our example it work like a
'FUU'.strip.downcase.to_sym
-
.headers- returns array of headers with applied key modifier and with range that define position column in the line. -
.values- returns array of hashes with applied range to corresponding line -
.dynamic_offseted_values- documentation in progress
- Fork it ( https://github.com/X1ting/dost/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request