Class: Cnab240::Lote
- Inherits:
-
Object
- Object
- Cnab240::Lote
- Defined in:
- lib/cnab240/lote.rb,
lib/cnab240/lote/v40/boletos/header.rb,
lib/cnab240/lote/v40/boletos/trailer.rb
Defined Under Namespace
Modules: V40
Instance Attribute Summary collapse
-
#arquivo ⇒ Object
Returns the value of attribute arquivo.
-
#header ⇒ Object
Returns the value of attribute header.
-
#operacao ⇒ Object
Returns the value of attribute operacao.
-
#segmentos ⇒ Object
Returns the value of attribute segmentos.
-
#tipo ⇒ Object
Returns the value of attribute tipo.
-
#trailer ⇒ Object
Returns the value of attribute trailer.
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #auto_fill ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Lote
constructor
A new instance of Lote.
- #linhas ⇒ Object
- #read_segmento(s, _line) ⇒ Object
- #string ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Lote
Returns a new instance of Lote.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cnab240/lote.rb', line 10 def initialize( = {}) @segmentos = [] @operacao ||= [:operacao] @tipo ||= [:tipo] @versao ||= [:versao] @fallback ||= [:fallback] @versao ||= 'V86' fail "Operacao '#{operacao}' nao suportada na versao #{@versao}" 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
#arquivo ⇒ Object
Returns the value of attribute arquivo.
8 9 10 |
# File 'lib/cnab240/lote.rb', line 8 def arquivo @arquivo end |
#header ⇒ Object
Returns the value of attribute header.
3 4 5 |
# File 'lib/cnab240/lote.rb', line 3 def header @header end |
#operacao ⇒ Object
Returns the value of attribute operacao.
6 7 8 |
# File 'lib/cnab240/lote.rb', line 6 def operacao @operacao end |
#segmentos ⇒ Object
Returns the value of attribute segmentos.
4 5 6 |
# File 'lib/cnab240/lote.rb', line 4 def segmentos @segmentos end |
#tipo ⇒ Object
Returns the value of attribute tipo.
7 8 9 |
# File 'lib/cnab240/lote.rb', line 7 def tipo @tipo end |
#trailer ⇒ Object
Returns the value of attribute trailer.
5 6 7 |
# File 'lib/cnab240/lote.rb', line 5 def trailer @trailer end |
Instance Method Details
#<<(s) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cnab240/lote.rb', line 35 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_fill ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cnab240/lote.rb', line 63 def auto_fill trailer.totais_qtde_registros = (segmentos.length + 2).to_s if trailer.respond_to?(:totais_valor) _total = 0 segmentos.each { |seg| _total += seg[:credito_valor_pagamento].to_i } trailer.totais_valor = _total.to_s end # Quando o lote é de boletos if trailer.respond_to?(:qtde_cobranca_simples) _total = 0 _qtde = 0 segmentos.each do |seg| next unless seg.class.to_s =~ /SegmentoP/ _qtde += 1 _total += seg[:valor].to_i end trailer.qtde_cobranca_simples = _qtde.to_s trailer.total_cobranca_simples = _total.to_s end end |
#linhas ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cnab240/lote.rb', line 48 def linhas auto_fill if Cnab240.auto_fill_enabled seg_array = [] 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
29 30 31 32 33 |
# File 'lib/cnab240/lote.rb', line 29 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 |
#string ⇒ Object
59 60 61 |
# File 'lib/cnab240/lote.rb', line 59 def string linhas.join("\n") end |