<commit_before>module Cnab240::Arquivo
	class Arquivo
		attr_accessor :header
		attr_accessor :lotes
		attr_accessor :trailer

		def initialize
			@header = Header.new
			@trailer = Trailer.new
			@lotes = []
		end


		def linhas
			a = Array.new
			a << @header.linha
			@lotes.each do |lote|
				lote.linhas.each do |linha|
					a << linha
				end
			end 
			a << @trailer.linha
			a
		end

		def string
			linhas.join("\n")
		end

		def save_to_file(filename)
			begin
				File.delete(filename) # LoL
			rescue
			end
			File.open(filename, 'w') {|f| f.write(string) }
		end

		def self.load_from_file(filename) # usar IO, blah, tanto faz :D
			arquivos = []
			line_number = 0
			File.open(filename, "r").each_line do |line|
				line.gsub!("\n", "")
				line_number = line_number + 1
				raise "Invalid line length: #{line.length} expected 240 at line number #{line_number}\n\t Line: [#{line}]" unless line.length == 240
				case line[7]
				when '0' # header de arquivo
					arquivos << Arquivo.new
					arquivos.last.header = Header.read(line)
				when '1'
				when '2'
				when '3'
				when '4'
				when '5'
				when '9'
					arquivos.last.header = Trailer.read(line)
				else
					raise 'Invalid tipo de registro: #{line[7]}.'<commit_msg>Adds 1.8.7 compat<commit_after>module Cnab240::Arquivo
	class Arquivo
		attr_accessor :header
		attr_accessor :lotes
		attr_accessor :trailer

		def initialize
			@header = Header.new
			@trailer = Trailer.new
			@lotes = []
		end


		def linhas
			a = Array.new
			a << @header.linha
			@lotes.each do |lote|
				lote.linhas.each do |linha|
					a << linha
				end
			end 
			a << @trailer.linha
			a
		end

		def string
			linhas.join("\n")
		end

		def save_to_file(filename)
			begin
				File.delete(filename) # LoL
			rescue
			end
			File.open(filename, 'w') {|f| f.write(string) }
		end

		def self.load_from_file(filename) # usar IO, blah, tanto faz :D
			arquivos = []
			line_number = 0
			File.open(filename, "r").each_line do |line|
				line.gsub!("\n", "")
				line_number = line_number + 1
				raise "Invalid line length: #{line.length} expected 240 at line number #{line_number}\n\t Line: [#{line}]" unless line.length == 240
				case line[7..7] # ruby 1.8.7 requires this fuck
				when '0' # header de arquivo
					arquivos << Arquivo.new
					arquivos.last.header = Header.read(line)
				when '1'
				when '2'
				when '3'
				when '4'
				when '5'
				when '9'
					arquivos.last.header = Trailer.read(line)
				else
					raise "Invalid tipo de registro: #{line[7]} at line #{line_number} \n\t Line: [#{line}]"
{'fraction_non_alphanumeric': 0.1285936285936286, 'fraction_numerical': 0.01825951825951826, 'mean_word_length': 2.668091168091168, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7532917', 'n_tokens_mistral': 1228, 'n_tokens_neox': 968, 'n_words': 254}