[Solved] Parse of .txt on ruby


You can use CSV for parsing files with separators, e.g.:

require 'csv'

CSV.foreach('your_file.txt', col_sep: "\t", headers: true).map do |row|
  row.to_h
end
#=> [{"purchaser"=>"João", "name"=>"St", "item"=>"R$20", "description"=>"off" ...}, 
#    {"purchaser"=>"Amy", "name"=>"Rd", "item"=>"awesome", "description"=>"of", ..}, ...]

It seems like this data is ready to process. A more common way is using comma-separated value for files like this, so I would suggest you change file format if you can.

solved Parse of .txt on ruby