Class: Cnab240::Lote

Inherits:
Object
  • Object
show all
Defined in:
lib/cnab240/arquivo/lote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Lote

Returns a new instance of Lote.

Yields:

  • (_self)

Yield Parameters:

  • _self (Cnab240::Lote)

    the object that the method was called on



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cnab240/arquivo/lote.rb', line 11

def initialize(options = {})
	@segmentos = []
	
	@operacao ||= options[:operacao]
	@tipo ||= options[:tipo]
	@versao ||= options[:versao]
	@fallback ||= options[:fallback]
	@versao ||= 'V86'

	raise "Operacao nao suportada: #{operacao}" if ESTRUTURA[@versao][operacao].nil?

	estrutura = ESTRUTURA[@versao][operacao]

	@header = estrutura[:header].new 
	@trailer = estrutura[:trailer].new

	yield self if block_given?
end

Instance Attribute Details

#arquivoObject

Returns the value of attribute arquivo.



9
10
11
# File 'lib/cnab240/arquivo/lote.rb', line 9

def arquivo
  @arquivo
end

#headerObject

Returns the value of attribute header.



4
5
6
# File 'lib/cnab240/arquivo/lote.rb', line 4

def header
  @header
end

#operacaoObject

Returns the value of attribute operacao.



7
8
9
# File 'lib/cnab240/arquivo/lote.rb', line 7

def operacao
  @operacao
end

#segmentosObject

Returns the value of attribute segmentos.



5
6
7
# File 'lib/cnab240/arquivo/lote.rb', line 5

def segmentos
  @segmentos
end

#tipoObject

Returns the value of attribute tipo.



8
9
10
# File 'lib/cnab240/arquivo/lote.rb', line 8

def tipo
  @tipo
end

#trailerObject

Returns the value of attribute trailer.



6
7
8
# File 'lib/cnab240/arquivo/lote.rb', line 6

def trailer
  @trailer
end

Instance Method Details

#<<(s) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cnab240/arquivo/lote.rb', line 36

def <<(s)
	versao = arquivo.versao unless arquivo.nil?
	versao ||= @versao
	case s 
	when Symbol, String
		segmentos << seg = eval("Cnab240::#{versao}::Segmento#{s.to_s.upcase}.new")	
	else
		segmentos << seg = s
	end
	seg.lote = self
	seg
end

#auto_fillObject



65
66
67
68
# File 'lib/cnab240/arquivo/lote.rb', line 65

def auto_fill
	# totais_qtde_registros
	
end

#linhasObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cnab240/arquivo/lote.rb', line 49

def linhas
	self.auto_fill if Cnab240.auto_fill_enabled
	seg_array = []
	estrutura = ESTRUTURA[@versao][operacao]
	seg_array << @header.linha
	segmentos.each do |s|
		seg_array << s.linha 
	end
	seg_array << @trailer.linha
	seg_array
end

#read_segmento(s, line) ⇒ Object



30
31
32
33
34
# File 'lib/cnab240/arquivo/lote.rb', line 30

def read_segmento(s, line)
	versao = arquivo.versao unless arquivo.nil?
versao ||= @versao
	segmentos << seg = eval("Cnab240::#{versao}::Segmento#{s.to_s.upcase}.read(line)")
end

#stringObject



61
62
63
# File 'lib/cnab240/arquivo/lote.rb', line 61

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