Class: Cnab240::Builder
- Inherits:
-
Object
- Object
- Cnab240::Builder
- Defined in:
- lib/cnab240/arquivo/builder.rb
Constant Summary collapse
- HEADER_ARQUIVO =
'0'
- HEADER_LOTE =
'1'
- INICIAIS_LOTE =
'2'
- DETALHE =
'3'
- FINAIS_LOTE =
'4'
- TRAILER_LOTE =
'5'
- TRAILER_ARQUIVO =
'9'
- RANGE_TIPO_REGISTRO =
7..7
- RANGE_LAYOUT_ARQUIVO =
163..165
- RANGE_HEADER_LOTE =
13..15
- RANGE_TIPO_OPERACAO_DETALHE =
13..13
Instance Attribute Summary collapse
-
#arquivos ⇒ Object
Returns the value of attribute arquivos.
Instance Method Summary collapse
-
#initialize(filename = nil) ⇒ Builder
constructor
A new instance of Builder.
- #load_from_file(filename) ⇒ Object
Constructor Details
#initialize(filename = nil) ⇒ Builder
Returns a new instance of Builder.
19 20 21 |
# File 'lib/cnab240/arquivo/builder.rb', line 19 def initialize(filename = nil) load_from_file(filename) unless filename.nil? end |
Instance Attribute Details
#arquivos ⇒ Object
Returns the value of attribute arquivos.
17 18 19 |
# File 'lib/cnab240/arquivo/builder.rb', line 17 def arquivos @arquivos end |
Instance Method Details
#load_from_file(filename) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cnab240/arquivo/builder.rb', line 23 def load_from_file(filename) @arquivos = [] line_number = 0 File.open(filename, "r").each_line do |line| check_line_encoding line, ++line_number case line[RANGE_TIPO_REGISTRO] when HEADER_ARQUIVO find_header_arquivo line, line_number when HEADER_LOTE find_header_lote line, line_number when INICIAIS_LOTE raise NotImplementedError.new("Tipo de registro nao suportado") when DETALHE find_segmento line, line_number when FINAIS_LOTE raise NotImplementedError.new("Tipo de registro not implemented") when TRAILER_LOTE arquivos.last.lotes.last.trailer.read(line) when TRAILER_ARQUIVO arquivos.last.trailer = Trailer.read(line) else raise "Invalid tipo de registro: #{line[RANGE_TIPO_REGISTRO]} at line #{line_number} \n\t Line: [#{line}]" end end arquivos end |