brcobranca 9.2.4 → 10.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -9
- data/HISTORY.md +71 -0
- data/README.md +47 -54
- data/Rakefile +4 -4
- data/lib/brcobranca/arquivos/logos/ailos.eps +412 -0
- data/lib/brcobranca/arquivos/logos/ailos_carne.eps +412 -0
- data/lib/brcobranca/arquivos/logos/safra.eps +0 -0
- data/lib/brcobranca/arquivos/logos/safra_carne.eps +0 -0
- data/lib/brcobranca/boleto/{cecred.rb → ailos.rb} +7 -5
- data/lib/brcobranca/boleto/banco_brasil.rb +9 -5
- data/lib/brcobranca/boleto/banco_brasilia.rb +5 -5
- data/lib/brcobranca/boleto/banco_nordeste.rb +4 -3
- data/lib/brcobranca/boleto/banestes.rb +4 -3
- data/lib/brcobranca/boleto/banrisul.rb +4 -3
- data/lib/brcobranca/boleto/base.rb +12 -7
- data/lib/brcobranca/boleto/bradesco.rb +4 -3
- data/lib/brcobranca/boleto/caixa.rb +10 -8
- data/lib/brcobranca/boleto/citibank.rb +9 -8
- data/lib/brcobranca/boleto/credisis.rb +6 -4
- data/lib/brcobranca/boleto/hsbc.rb +8 -6
- data/lib/brcobranca/boleto/itau.rb +5 -5
- data/lib/brcobranca/boleto/safra.rb +4 -4
- data/lib/brcobranca/boleto/santander.rb +4 -2
- data/lib/brcobranca/boleto/sicoob.rb +4 -3
- data/lib/brcobranca/boleto/sicredi.rb +6 -3
- data/lib/brcobranca/boleto/template/base.rb +2 -3
- data/lib/brcobranca/boleto/template/rghost.rb +18 -13
- data/lib/brcobranca/boleto/template/rghost_carne.rb +18 -12
- data/lib/brcobranca/boleto/unicred.rb +61 -103
- data/lib/brcobranca/calculo.rb +14 -9
- data/lib/brcobranca/calculo_data.rb +6 -5
- data/lib/brcobranca/currency.rb +10 -10
- data/lib/brcobranca/formatacao.rb +2 -1
- data/lib/brcobranca/formatacao_string.rb +7 -6
- data/lib/brcobranca/limpeza.rb +3 -3
- data/lib/brcobranca/remessa/base.rb +7 -10
- data/lib/brcobranca/remessa/cnab240/{cecred.rb → ailos.rb} +18 -15
- data/lib/brcobranca/remessa/cnab240/banco_brasil.rb +14 -11
- data/lib/brcobranca/remessa/cnab240/base.rb +56 -39
- data/lib/brcobranca/remessa/cnab240/base_correspondente.rb +25 -17
- data/lib/brcobranca/remessa/cnab240/caixa.rb +21 -13
- data/lib/brcobranca/remessa/cnab240/sicoob.rb +33 -30
- data/lib/brcobranca/remessa/cnab240/sicoob_banco_brasil.rb +14 -7
- data/lib/brcobranca/remessa/cnab240/sicredi.rb +28 -22
- data/lib/brcobranca/remessa/cnab240/unicred.rb +2 -1
- data/lib/brcobranca/remessa/cnab400/banco_brasil.rb +9 -9
- data/lib/brcobranca/remessa/cnab400/banco_brasilia.rb +29 -28
- data/lib/brcobranca/remessa/cnab400/banco_nordeste.rb +11 -10
- data/lib/brcobranca/remessa/cnab400/banrisul.rb +13 -10
- data/lib/brcobranca/remessa/cnab400/base.rb +22 -9
- data/lib/brcobranca/remessa/cnab400/bradesco.rb +30 -5
- data/lib/brcobranca/remessa/cnab400/citibank.rb +6 -5
- data/lib/brcobranca/remessa/cnab400/credisis.rb +7 -5
- data/lib/brcobranca/remessa/cnab400/itau.rb +9 -6
- data/lib/brcobranca/remessa/cnab400/santander.rb +17 -15
- data/lib/brcobranca/remessa/cnab400/sicoob.rb +8 -11
- data/lib/brcobranca/remessa/cnab400/unicred.rb +185 -69
- data/lib/brcobranca/remessa/pagamento.rb +43 -11
- data/lib/brcobranca/retorno/base.rb +5 -43
- data/lib/brcobranca/retorno/cnab240/{cecred.rb → ailos.rb} +12 -10
- data/lib/brcobranca/retorno/cnab240/base.rb +8 -9
- data/lib/brcobranca/retorno/cnab240/caixa.rb +4 -5
- data/lib/brcobranca/retorno/cnab240/santander.rb +12 -8
- data/lib/brcobranca/retorno/cnab240/sicoob.rb +11 -9
- data/lib/brcobranca/retorno/cnab240/sicredi.rb +12 -9
- data/lib/brcobranca/retorno/cnab400/banco_brasil.rb +3 -3
- data/lib/brcobranca/retorno/cnab400/banco_brasilia.rb +2 -1
- data/lib/brcobranca/retorno/cnab400/banco_nordeste.rb +2 -1
- data/lib/brcobranca/retorno/cnab400/banrisul.rb +1 -1
- data/lib/brcobranca/retorno/cnab400/base.rb +13 -12
- data/lib/brcobranca/retorno/cnab400/bradesco.rb +4 -4
- data/lib/brcobranca/retorno/cnab400/credisis.rb +2 -1
- data/lib/brcobranca/retorno/cnab400/itau.rb +6 -5
- data/lib/brcobranca/retorno/cnab400/santander.rb +8 -7
- data/lib/brcobranca/retorno/cnab400/unicred.rb +63 -58
- data/lib/brcobranca/retorno/retorno_cbr643.rb +1 -2
- data/lib/brcobranca/retorno/retorno_cnab240.rb +11 -9
- data/lib/brcobranca/retorno/retorno_cnab400.rb +6 -5
- data/lib/brcobranca/util/date.rb +2 -1
- data/lib/brcobranca/util/empresa.rb +2 -1
- data/lib/brcobranca/util/errors.rb +31 -31
- data/lib/brcobranca/validations.rb +127 -151
- data/lib/brcobranca/version.rb +2 -3
- data/lib/brcobranca.rb +5 -5
- data/spec/brcobranca/base_spec.rb +20 -11
- data/spec/brcobranca/boleto/{cecred_spec.rb → ailos_spec.rb} +13 -12
- data/spec/brcobranca/boleto/banco_brasil_spec.rb +14 -12
- data/spec/brcobranca/boleto/banco_brasilia_spec.rb +11 -10
- data/spec/brcobranca/boleto/banco_nordeste_spec.rb +2 -3
- data/spec/brcobranca/boleto/banestes_spec.rb +10 -11
- data/spec/brcobranca/boleto/banrisul_spec.rb +10 -12
- data/spec/brcobranca/boleto/bradesco_spec.rb +36 -33
- data/spec/brcobranca/boleto/caixa_spec.rb +11 -12
- data/spec/brcobranca/boleto/citibank_spec.rb +10 -11
- data/spec/brcobranca/boleto/credisis_spec.rb +18 -17
- data/spec/brcobranca/boleto/hsbc_spec.rb +9 -10
- data/spec/brcobranca/boleto/itau_spec.rb +11 -12
- data/spec/brcobranca/boleto/safra_spec.rb +10 -11
- data/spec/brcobranca/boleto/santander_spec.rb +9 -10
- data/spec/brcobranca/boleto/sicoob_spec.rb +10 -11
- data/spec/brcobranca/boleto/sicredi_spec.rb +14 -10
- data/spec/brcobranca/boleto/unicred_spec.rb +28 -38
- data/spec/brcobranca/boletos_em_lote_spec.rb +7 -7
- data/spec/brcobranca/calculo_data_spec.rb +2 -2
- data/spec/brcobranca/calculo_spec.rb +13 -11
- data/spec/brcobranca/currency_spec.rb +26 -26
- data/spec/brcobranca/formatacao_spec.rb +2 -2
- data/spec/brcobranca/formatacao_string_spec.rb +10 -4
- data/spec/brcobranca/limpeza_spec.rb +2 -2
- data/spec/brcobranca/remessa/base_spec.rb +1 -2
- data/spec/brcobranca/remessa/cnab240/{cecred_spec.rb → ailos_spec.rb} +48 -47
- data/spec/brcobranca/remessa/cnab240/banco_brasil_spec.rb +18 -13
- data/spec/brcobranca/remessa/cnab240/base_spec.rb +33 -10
- data/spec/brcobranca/remessa/cnab240/caixa_spec.rb +19 -17
- data/spec/brcobranca/remessa/cnab240/sicoob_banco_brasil_spec.rb +12 -8
- data/spec/brcobranca/remessa/cnab240/sicoob_spec.rb +28 -26
- data/spec/brcobranca/remessa/cnab240/sicredi_spec.rb +12 -10
- data/spec/brcobranca/remessa/cnab240/unicred_spec.rb +11 -9
- data/spec/brcobranca/remessa/cnab400/banco_brasil_spec.rb +6 -3
- data/spec/brcobranca/remessa/cnab400/banco_brasilia_spec.rb +24 -19
- data/spec/brcobranca/remessa/cnab400/banco_nordeste_spec.rb +19 -14
- data/spec/brcobranca/remessa/cnab400/banrisul_spec.rb +17 -15
- data/spec/brcobranca/remessa/cnab400/base_spec.rb +23 -8
- data/spec/brcobranca/remessa/cnab400/bradesco_spec.rb +19 -17
- data/spec/brcobranca/remessa/cnab400/citibank_spec.rb +14 -12
- data/spec/brcobranca/remessa/cnab400/credisis_spec.rb +21 -19
- data/spec/brcobranca/remessa/cnab400/itau_spec.rb +18 -16
- data/spec/brcobranca/remessa/cnab400/santander_spec.rb +24 -22
- data/spec/brcobranca/remessa/cnab400/sicoob_spec.rb +20 -20
- data/spec/brcobranca/remessa/cnab400/unicred_spec.rb +167 -166
- data/spec/brcobranca/remessa/pagamento_spec.rb +16 -15
- data/spec/brcobranca/retorno/cnab240/base_spec.rb +10 -9
- data/spec/brcobranca/retorno/cnab240/cecred_spec.rb +4 -2
- data/spec/brcobranca/retorno/cnab240/santander_spec.rb +2 -0
- data/spec/brcobranca/retorno/cnab240/sicoob_spec.rb +2 -0
- data/spec/brcobranca/retorno/cnab240/sicredi_spec.rb +2 -0
- data/spec/brcobranca/retorno/cnab400/banco_brasilia_spec.rb +2 -1
- data/spec/brcobranca/retorno/cnab400/banco_nordeste_spec.rb +2 -1
- data/spec/brcobranca/retorno/cnab400/banrisul_spec.rb +2 -1
- data/spec/brcobranca/retorno/cnab400/base_spec.rb +25 -25
- data/spec/brcobranca/retorno/cnab400/bradesco_spec.rb +2 -1
- data/spec/brcobranca/retorno/cnab400/credisis_spec.rb +5 -4
- data/spec/brcobranca/retorno/cnab400/itau_spec.rb +4 -2
- data/spec/brcobranca/retorno/cnab400/santander_spec.rb +2 -1
- data/spec/brcobranca/retorno/cnab400/unicred_spec.rb +28 -32
- data/spec/brcobranca/retorno/retorno_cbr643_spec.rb +2 -2
- data/spec/brcobranca/retorno/retorno_cnab400_spec.rb +2 -1
- data/spec/brcobranca/retorno/retorno_cnab_240_spec.rb +2 -1
- data/spec/brcobranca/rghost_spec.rb +4 -4
- data/spec/brcobranca/util/empresa_spec.rb +1 -2
- data/spec/brcobranca_spec.rb +1 -2
- metadata +85 -162
- data/spec/arquivos/CBR64310.RET +0 -28
- data/spec/arquivos/CNAB240.RET +0 -74
- data/spec/arquivos/CNAB240CECRED.RET +0 -10
- data/spec/arquivos/CNAB240SANTANDER.RET +0 -8
- data/spec/arquivos/CNAB240SICOOB.RET +0 -10
- data/spec/arquivos/CNAB240SICREDI.CRT +0 -8
- data/spec/arquivos/CNAB400.RET +0 -54
- data/spec/arquivos/CNAB400BANCOBRASILIA.RET +0 -3
- data/spec/arquivos/CNAB400BANCONORDESTE.RET +0 -3
- data/spec/arquivos/CNAB400BANRISUL.RET +0 -3
- data/spec/arquivos/CNAB400BRADESCO.RET +0 -8
- data/spec/arquivos/CNAB400CREDISIS.RET +0 -3
- data/spec/arquivos/CNAB400ITAU.RET +0 -54
- data/spec/arquivos/CNAB400SANTANDER.RET +0 -54
- data/spec/arquivos/CNAB400UNICRED.RET +0 -3
- data/spec/fixtures/remessa/remessa-banco-brasil-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-banco-brasilia-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-banco-nordeste-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-banco_brasil-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-bancoob-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-banrisul-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-bradesco-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-caixa-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-cecred-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-citibank-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-credisis-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-itau-cnab400.rem +0 -4
- data/spec/fixtures/remessa/remessa-santander-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-sicoob-cnab400.rem +0 -3
- data/spec/fixtures/remessa/remessa-sicoob-correspondente-bb-cnab240.rem +0 -4
- data/spec/fixtures/remessa/remessa-sicredi-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-unicred-cnab240.rem +0 -7
- data/spec/fixtures/remessa/remessa-unicred-cnab400.rem +0 -3
- data/spec/spec.opts +0 -8
- data/spec/spec_helper.rb +0 -38
- data/spec/support/remessa_helpers.rb +0 -13
- data/spec/support/shared_examples/busca_logotipo.rb +0 -15
- data/spec/support/shared_examples/cnab240.rb +0 -259
- data/spec/support/shared_examples/cnab400.rb +0 -180
- data/spec/support/shared_examples/formatos_validos.rb +0 -36
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Brcobranca
|
2
4
|
module Util
|
3
5
|
class Errors
|
4
|
-
|
5
6
|
include Enumerable
|
6
7
|
|
7
|
-
CALLBACKS_OPTIONS = [
|
8
|
-
MESSAGE_OPTIONS = [:message]
|
8
|
+
CALLBACKS_OPTIONS = %i[if unless on allow_nil allow_blank strict].freeze
|
9
|
+
MESSAGE_OPTIONS = [:message].freeze
|
9
10
|
|
10
11
|
attr_reader :messages, :details
|
11
12
|
|
@@ -26,51 +27,50 @@ module Brcobranca
|
|
26
27
|
def size
|
27
28
|
@messages.values.flatten.size
|
28
29
|
end
|
29
|
-
alias
|
30
|
+
alias count size
|
30
31
|
|
31
|
-
def generate_message(attribute, type = :invalid,
|
32
|
+
def generate_message(attribute, type = :invalid, _options = {})
|
32
33
|
:"errors.attributes.#{attribute}.#{type}"
|
33
34
|
end
|
34
35
|
|
35
36
|
def full_messages
|
36
37
|
@messages.values.flatten
|
37
38
|
end
|
38
|
-
alias
|
39
|
+
alias to_a full_messages
|
39
40
|
|
40
41
|
private
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def apply_default_array(hash)
|
44
|
+
hash.default_proc = proc { |h, key| h[key] = [] }
|
45
|
+
hash
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
def normalize_message(attribute, message, options)
|
49
|
+
case message
|
50
|
+
when Symbol
|
51
|
+
generate_message(attribute, message, except(options, *CALLBACKS_OPTIONS))
|
52
|
+
else
|
53
|
+
if message.start_with?(variable_name(attribute))
|
54
|
+
message
|
51
55
|
else
|
52
|
-
|
53
|
-
message
|
54
|
-
else
|
55
|
-
"#{variable_name(attribute)} #{message}"
|
56
|
-
end
|
56
|
+
"#{variable_name(attribute)} #{message}"
|
57
57
|
end
|
58
58
|
end
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def except(hash, *keys)
|
65
|
-
dup = hash.dup
|
66
|
-
keys.each { |key| dup.delete(key) }
|
67
|
-
dup
|
68
|
-
end
|
61
|
+
def normalize_detail(message, options)
|
62
|
+
{ error: message }.merge(except(options, *CALLBACKS_OPTIONS + MESSAGE_OPTIONS))
|
63
|
+
end
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
def except(hash, *keys)
|
66
|
+
dup = hash.dup
|
67
|
+
keys.each { |key| dup.delete(key) }
|
68
|
+
dup
|
69
|
+
end
|
73
70
|
|
71
|
+
def variable_name(symbol)
|
72
|
+
symbol.to_s.tr('_', ' ').capitalize
|
73
|
+
end
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -1,25 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# @author Eduardo Reboucas
|
3
4
|
require 'brcobranca/util/errors'
|
4
5
|
|
5
6
|
module Brcobranca
|
6
|
-
|
7
7
|
# Métodos auxiliares de validação para evitar ActiveSupport e ActiveModel com
|
8
8
|
# mínimo de impacto nas definições das validações existentes
|
9
9
|
|
10
10
|
module Validations
|
11
|
-
|
12
11
|
def self.included(base)
|
13
12
|
base.extend(ClassMethods)
|
14
13
|
end
|
15
14
|
|
16
15
|
module ClassMethods
|
17
|
-
|
18
|
-
attr_reader :presences
|
19
|
-
attr_reader :lengths
|
20
|
-
attr_reader :numericals
|
21
|
-
attr_reader :inclusions
|
22
|
-
attr_reader :eachs
|
16
|
+
attr_reader :presences, :lengths, :numericals, :inclusions, :eachs
|
23
17
|
|
24
18
|
def validates_presence_of(*attr_names)
|
25
19
|
@presences ||= []
|
@@ -48,9 +42,7 @@ module Brcobranca
|
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
51
|
-
def with_options(options, &block)
|
52
|
-
end
|
53
|
-
|
45
|
+
def with_options(options, &block); end
|
54
46
|
end
|
55
47
|
|
56
48
|
def errors
|
@@ -58,15 +50,15 @@ module Brcobranca
|
|
58
50
|
end
|
59
51
|
|
60
52
|
def valid?
|
61
|
-
#puts "** #{self.class}"
|
62
|
-
#puts "** #{self.class.superclass}"
|
53
|
+
# puts "** #{self.class}"
|
54
|
+
# puts "** #{self.class.superclass}"
|
63
55
|
all_valid = true
|
64
|
-
all_valid = false
|
65
|
-
all_valid = false
|
66
|
-
all_valid = false
|
67
|
-
all_valid = false
|
68
|
-
all_valid = false
|
69
|
-
|
56
|
+
all_valid = false unless check_eachs
|
57
|
+
all_valid = false unless check_presences
|
58
|
+
all_valid = false unless check_numericals
|
59
|
+
all_valid = false unless check_lengths
|
60
|
+
all_valid = false unless check_inclusions
|
61
|
+
all_valid
|
70
62
|
end
|
71
63
|
|
72
64
|
def invalid?
|
@@ -75,158 +67,142 @@ module Brcobranca
|
|
75
67
|
|
76
68
|
private
|
77
69
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
eachs.each do |attr_name, block|
|
91
|
-
value = ''
|
92
|
-
begin
|
93
|
-
value = self.send(attr_name)
|
94
|
-
rescue
|
95
|
-
end
|
96
|
-
block.call(self, attr_name, value)
|
70
|
+
def check_eachs
|
71
|
+
eachs = {}
|
72
|
+
eachs.merge!(self.class.superclass.superclass.eachs || {}) if self.class.superclass.superclass.respond_to?(:eachs)
|
73
|
+
eachs.merge!(self.class.superclass.eachs || {}) if self.class.superclass.respond_to?(:eachs)
|
74
|
+
eachs.merge!(self.class.eachs) if self.class.eachs
|
75
|
+
return true if eachs.keys.size.zero?
|
76
|
+
|
77
|
+
eachs.each do |attr_name, block|
|
78
|
+
value = ''
|
79
|
+
begin
|
80
|
+
value = send(attr_name)
|
81
|
+
rescue StandardError
|
97
82
|
end
|
98
|
-
|
83
|
+
block.call(self, attr_name, value)
|
99
84
|
end
|
85
|
+
errors.size.zero?
|
86
|
+
end
|
100
87
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
presence.select { |p| p.is_a? Symbol}.each do |variable|
|
115
|
-
if blank?(self.send(variable))
|
116
|
-
all_present = false
|
117
|
-
errors.add variable, presence[-1][:message]
|
118
|
-
end
|
88
|
+
def check_presences
|
89
|
+
presences = []
|
90
|
+
if self.class.superclass.superclass.respond_to?(:presences)
|
91
|
+
presences = self.class.superclass.superclass.presences || []
|
92
|
+
end
|
93
|
+
presences += self.class.superclass.presences || [] if self.class.superclass.respond_to?(:presences)
|
94
|
+
presences += self.class.presences if self.class.presences
|
95
|
+
all_present = true
|
96
|
+
presences.each do |presence|
|
97
|
+
presence.select { |p| p.is_a? Symbol }.each do |variable|
|
98
|
+
if blank?(send(variable))
|
99
|
+
all_present = false
|
100
|
+
errors.add variable, presence[-1][:message]
|
119
101
|
end
|
120
102
|
end
|
121
|
-
return all_present
|
122
103
|
end
|
104
|
+
all_present
|
105
|
+
end
|
123
106
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
if self.respond_to?(variable) && self.send(variable) && (self.send(variable).to_s =~ /\A[+-]?\d+\z/).nil?
|
137
|
-
all_numerical = false
|
138
|
-
errors.add variable, numerical[-1][:message]
|
139
|
-
end
|
107
|
+
def check_numericals
|
108
|
+
numericals = []
|
109
|
+
numericals = self.class.superclass.numericals || [] if self.class.superclass.respond_to?(:numericals)
|
110
|
+
numericals += self.class.numericals if self.class.numericals
|
111
|
+
return true unless numericals
|
112
|
+
|
113
|
+
all_numerical = true
|
114
|
+
numericals.each do |numerical|
|
115
|
+
numerical.select { |p| p.is_a? Symbol }.each do |variable|
|
116
|
+
if respond_to?(variable) && send(variable) && (send(variable).to_s =~ /\A[+-]?\d+\z/).nil?
|
117
|
+
all_numerical = false
|
118
|
+
errors.add variable, numerical[-1][:message]
|
140
119
|
end
|
141
120
|
end
|
142
|
-
return all_numerical
|
143
121
|
end
|
122
|
+
all_numerical
|
123
|
+
end
|
144
124
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
125
|
+
def check_lengths
|
126
|
+
lengths = []
|
127
|
+
lengths = self.class.superclass.superclass.lengths || [] if self.class.superclass.superclass.respond_to?(:lengths)
|
128
|
+
lengths += self.class.superclass.lengths || [] if self.class.superclass.respond_to?(:lengths)
|
129
|
+
lengths += self.class.lengths if self.class.lengths
|
130
|
+
return true unless lengths
|
131
|
+
|
132
|
+
all_checked = true
|
133
|
+
lengths.each do |rule|
|
134
|
+
variable = rule[0]
|
135
|
+
next unless respond_to?(variable)
|
136
|
+
|
137
|
+
value = send(variable)
|
138
|
+
if rule[-1][:in]
|
139
|
+
if !value
|
140
|
+
all_checked = false
|
141
|
+
errors.add variable, rule[-1][:message]
|
142
|
+
elsif value.size < rule[-1][:in].first || value.size > rule[-1][:in].last
|
143
|
+
all_checked = false
|
144
|
+
errors.add variable, rule[-1][:message]
|
145
|
+
end
|
155
146
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
if !value
|
164
|
-
all_checked = false
|
165
|
-
errors.add variable, rule[-1][:message]
|
166
|
-
elsif value.size < rule[-1][:in].first || value.size > rule[-1][:in].last
|
167
|
-
all_checked = false
|
168
|
-
errors.add variable, rule[-1][:message]
|
169
|
-
end
|
147
|
+
if rule[-1][:is]
|
148
|
+
if !value
|
149
|
+
all_checked = false
|
150
|
+
errors.add variable, rule[-1][:message]
|
151
|
+
elsif value.to_s.size != rule[-1][:is]
|
152
|
+
all_checked = false
|
153
|
+
errors.add variable, rule[-1][:message]
|
170
154
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
all_checked = false
|
177
|
-
errors.add variable, rule[-1][:message]
|
178
|
-
end
|
155
|
+
end
|
156
|
+
if rule[-1][:minimum] && rule[-1][:maximum]
|
157
|
+
if !value || value.size < rule[-1][:minimum] || value.size > rule[-1][:maximum]
|
158
|
+
all_checked = false
|
159
|
+
errors.add variable, rule[-1][:message]
|
179
160
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
elsif rule[-1][:maximum]
|
186
|
-
if value && value.size > rule[-1][:maximum]
|
187
|
-
all_checked = false
|
188
|
-
errors.add variable, rule[-1][:message]
|
189
|
-
end
|
161
|
+
elsif rule[-1][:maximum]
|
162
|
+
if value && value.size > rule[-1][:maximum]
|
163
|
+
all_checked = false
|
164
|
+
errors.add variable, rule[-1][:message]
|
190
165
|
end
|
191
166
|
end
|
192
|
-
return all_checked
|
193
167
|
end
|
168
|
+
all_checked
|
169
|
+
end
|
194
170
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
if self.class.superclass.respond_to?(:inclusions)
|
201
|
-
inclusions += self.class.superclass.inclusions || []
|
202
|
-
end
|
203
|
-
if self.class.inclusions
|
204
|
-
inclusions += self.class.inclusions
|
205
|
-
end
|
206
|
-
return true if !inclusions
|
207
|
-
all_checked = true
|
208
|
-
inclusions.each do |rule|
|
209
|
-
variable = rule[0]
|
210
|
-
next if !self.respond_to?(variable)
|
211
|
-
value = self.send(variable)
|
212
|
-
next if !value
|
213
|
-
if rule[-1][:in]
|
214
|
-
if !rule[-1][:in].include?(value)
|
215
|
-
all_checked = false
|
216
|
-
errors.add variable, rule[-1][:message]
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
return all_checked
|
171
|
+
def check_inclusions
|
172
|
+
inclusions = []
|
173
|
+
if self.class.superclass.superclass.respond_to?(:inclusions)
|
174
|
+
inclusions = self.class.superclass.superclass.inclusions || []
|
221
175
|
end
|
176
|
+
inclusions += self.class.superclass.inclusions || [] if self.class.superclass.respond_to?(:inclusions)
|
177
|
+
inclusions += self.class.inclusions if self.class.inclusions
|
178
|
+
return true unless inclusions
|
222
179
|
|
223
|
-
|
224
|
-
|
225
|
-
|
180
|
+
all_checked = true
|
181
|
+
inclusions.each do |rule|
|
182
|
+
variable = rule[0]
|
183
|
+
next unless respond_to?(variable)
|
184
|
+
|
185
|
+
value = send(variable)
|
186
|
+
next unless value
|
187
|
+
|
188
|
+
next unless rule[-1][:in]
|
226
189
|
|
227
|
-
|
228
|
-
|
229
|
-
|
190
|
+
unless rule[-1][:in].include?(value)
|
191
|
+
all_checked = false
|
192
|
+
errors.add variable, rule[-1][:message]
|
193
|
+
end
|
230
194
|
end
|
195
|
+
all_checked
|
196
|
+
end
|
197
|
+
|
198
|
+
def variable_name(symbol)
|
199
|
+
symbol.to_s.tr('_', ' ').capitalize
|
200
|
+
end
|
201
|
+
|
202
|
+
def blank?(obj)
|
203
|
+
return obj !~ /\S/ if obj.is_a? String
|
204
|
+
|
205
|
+
obj.respond_to?(:empty?) ? obj.empty? : !obj
|
206
|
+
end
|
231
207
|
end
|
232
208
|
end
|
data/lib/brcobranca/version.rb
CHANGED
data/lib/brcobranca.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
require 'brcobranca/calculo'
|
4
4
|
require 'brcobranca/limpeza'
|
5
5
|
require 'brcobranca/formatacao'
|
@@ -111,9 +111,9 @@ module Brcobranca
|
|
111
111
|
autoload :Banestes, 'brcobranca/boleto/banestes'
|
112
112
|
autoload :Banrisul, 'brcobranca/boleto/banrisul'
|
113
113
|
autoload :Credisis, 'brcobranca/boleto/credisis'
|
114
|
-
autoload :Cecred, 'brcobranca/boleto/cecred'
|
115
114
|
autoload :Safra, 'brcobranca/boleto/safra'
|
116
115
|
autoload :Citibank, 'brcobranca/boleto/citibank'
|
116
|
+
autoload :Ailos, 'brcobranca/boleto/ailos'
|
117
117
|
|
118
118
|
# Módulos para classes de template
|
119
119
|
module Template
|
@@ -146,10 +146,10 @@ module Brcobranca
|
|
146
146
|
module Cnab240
|
147
147
|
autoload :Base, 'brcobranca/retorno/cnab240/base'
|
148
148
|
autoload :Santander, 'brcobranca/retorno/cnab240/santander'
|
149
|
-
autoload :Cecred, 'brcobranca/retorno/cnab240/cecred'
|
150
149
|
autoload :Sicredi, 'brcobranca/retorno/cnab240/sicredi'
|
151
150
|
autoload :Sicoob, 'brcobranca/retorno/cnab240/sicoob'
|
152
151
|
autoload :Caixa, 'brcobranca/retorno/cnab240/caixa'
|
152
|
+
autoload :Ailos, 'brcobranca/retorno/cnab240/ailos'
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -177,12 +177,12 @@ module Brcobranca
|
|
177
177
|
autoload :Base, 'brcobranca/remessa/cnab240/base'
|
178
178
|
autoload :BaseCorrespondente, 'brcobranca/remessa/cnab240/base_correspondente'
|
179
179
|
autoload :Caixa, 'brcobranca/remessa/cnab240/caixa'
|
180
|
-
autoload :Cecred, 'brcobranca/remessa/cnab240/cecred'
|
181
180
|
autoload :BancoBrasil, 'brcobranca/remessa/cnab240/banco_brasil'
|
182
181
|
autoload :Sicoob, 'brcobranca/remessa/cnab240/sicoob'
|
183
182
|
autoload :SicoobBancoBrasil, 'brcobranca/remessa/cnab240/sicoob_banco_brasil'
|
184
183
|
autoload :Sicredi, 'brcobranca/remessa/cnab240/sicredi'
|
185
184
|
autoload :Unicred, 'brcobranca/remessa/cnab240/unicred'
|
185
|
+
autoload :Ailos, 'brcobranca/remessa/cnab240/ailos'
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe Brcobranca::Boleto::Base do
|
@@ -35,7 +35,7 @@ RSpec.describe Brcobranca::Boleto::Base do
|
|
35
35
|
expect(boleto_novo.valor).to eq(0.0)
|
36
36
|
expect(boleto_novo.valor_documento).to eq(0.0)
|
37
37
|
expect(boleto_novo.local_pagamento).to eql('QUALQUER BANCO ATÉ O VENCIMENTO')
|
38
|
-
expect(boleto_novo
|
38
|
+
expect(boleto_novo).not_to be_valid
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'Criar nova instancia com atributos válidos' do
|
@@ -59,7 +59,7 @@ RSpec.describe Brcobranca::Boleto::Base do
|
|
59
59
|
expect(boleto_novo.convenio).to be(12_387_989)
|
60
60
|
expect(boleto_novo.nosso_numero).to eql('777700168')
|
61
61
|
expect(boleto_novo.documento_numero).to eql('9999999')
|
62
|
-
expect(boleto_novo
|
62
|
+
expect(boleto_novo).to be_valid
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'Calcula agencia_dv' do
|
@@ -142,20 +142,29 @@ RSpec.describe Brcobranca::Boleto::Base do
|
|
142
142
|
|
143
143
|
it 'Mostrar aviso sobre sobrecarga de métodos padrões' do
|
144
144
|
boleto_novo = described_class.new(@valid_attributes)
|
145
|
-
expect
|
146
|
-
|
147
|
-
|
145
|
+
expect do
|
146
|
+
boleto_novo.codigo_barras_segunda_parte
|
147
|
+
end.to raise_error(Brcobranca::NaoImplementado,
|
148
|
+
'Sobreescreva este método na classe referente ao banco que você esta criando')
|
149
|
+
expect do
|
150
|
+
boleto_novo.nosso_numero_boleto
|
151
|
+
end.to raise_error(Brcobranca::NaoImplementado,
|
152
|
+
'Sobreescreva este método na classe referente ao banco que você esta criando')
|
153
|
+
expect do
|
154
|
+
boleto_novo.agencia_conta_boleto
|
155
|
+
end.to raise_error(Brcobranca::NaoImplementado,
|
156
|
+
'Sobreescreva este método na classe referente ao banco que você esta criando')
|
148
157
|
end
|
149
158
|
|
150
159
|
it 'Incluir módulos de template na classe' do
|
151
|
-
expect(described_class.respond_to
|
152
|
-
expect(described_class.respond_to
|
160
|
+
expect(described_class).to respond_to(:lote)
|
161
|
+
expect(described_class).to respond_to(:to)
|
153
162
|
end
|
154
163
|
|
155
164
|
it 'Incluir módulos de template na instancia' do
|
156
165
|
boleto_novo = described_class.new
|
157
|
-
expect(boleto_novo.respond_to
|
158
|
-
expect(boleto_novo.respond_to
|
166
|
+
expect(boleto_novo).to respond_to(:lote)
|
167
|
+
expect(boleto_novo).to respond_to(:to)
|
159
168
|
end
|
160
169
|
|
161
170
|
it 'data_documento em string' do
|
@@ -1,11 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
RSpec.describe Brcobranca::Boleto::
|
5
|
+
RSpec.describe Brcobranca::Boleto::Ailos do # :nodoc:[all]
|
5
6
|
before do
|
6
7
|
@valid_attributes = {
|
7
8
|
valor: 0.0,
|
8
|
-
local_pagamento: '
|
9
|
+
local_pagamento: 'Pagar preferencialmente nas cooperativas do Sistema AILOS.',
|
9
10
|
cedente: 'Kivanio Barbosa',
|
10
11
|
documento_cedente: '12345678912',
|
11
12
|
sacado: 'Claudio Pozzebom',
|
@@ -66,10 +67,10 @@ RSpec.describe Brcobranca::Boleto::Cecred do #:nodoc:[all]
|
|
66
67
|
expect(boleto_novo.data_processamento).to eql(Date.today)
|
67
68
|
expect(boleto_novo.data_vencimento).to eql(Date.today)
|
68
69
|
expect(boleto_novo.aceite).to eql('S')
|
69
|
-
expect(boleto_novo.quantidade).to
|
70
|
-
expect(boleto_novo.valor).to
|
71
|
-
expect(boleto_novo.valor_documento).to
|
72
|
-
expect(boleto_novo.local_pagamento).to eql('
|
70
|
+
expect(boleto_novo.quantidade).to be(1)
|
71
|
+
expect(boleto_novo.valor).to be(0.0)
|
72
|
+
expect(boleto_novo.valor_documento).to be(0.0)
|
73
|
+
expect(boleto_novo.local_pagamento).to eql('Pagar preferencialmente nas cooperativas do Sistema AILOS.')
|
73
74
|
expect(boleto_novo.carteira).to eql('01')
|
74
75
|
expect(boleto_novo.codigo_servico).to be_falsey
|
75
76
|
end
|
@@ -83,10 +84,10 @@ RSpec.describe Brcobranca::Boleto::Cecred do #:nodoc:[all]
|
|
83
84
|
expect(boleto_novo.data_processamento).to eql(Date.today)
|
84
85
|
expect(boleto_novo.data_vencimento).to eql(Date.today)
|
85
86
|
expect(boleto_novo.aceite).to eql('S')
|
86
|
-
expect(boleto_novo.quantidade).to
|
87
|
-
expect(boleto_novo.valor).to
|
88
|
-
expect(boleto_novo.valor_documento).to
|
89
|
-
expect(boleto_novo.local_pagamento).to eql('
|
87
|
+
expect(boleto_novo.quantidade).to be(1)
|
88
|
+
expect(boleto_novo.valor).to be(0.0)
|
89
|
+
expect(boleto_novo.valor_documento).to be(0.0)
|
90
|
+
expect(boleto_novo.local_pagamento).to eql('Pagar preferencialmente nas cooperativas do Sistema AILOS.')
|
90
91
|
expect(boleto_novo.cedente).to eql('Kivanio Barbosa')
|
91
92
|
expect(boleto_novo.documento_cedente).to eql('12345678912')
|
92
93
|
expect(boleto_novo.sacado).to eql('Claudio Pozzebom')
|
@@ -108,7 +109,7 @@ RSpec.describe Brcobranca::Boleto::Cecred do #:nodoc:[all]
|
|
108
109
|
expect(boleto_novo.codigo_barras_segunda_parte).to eql('0000001111111900000000101')
|
109
110
|
expect(boleto_novo.codigo_barras).to eql('08593643900000001000000001111111900000000101')
|
110
111
|
expect(boleto_novo.codigo_barras.linha_digitavel).to eql('08590.00002 01111.111900 00000.001016 3 64390000000100')
|
111
|
-
expect(boleto_novo.conta_corrente_dv).to
|
112
|
+
expect(boleto_novo.conta_corrente_dv).to be(9)
|
112
113
|
|
113
114
|
@valid_attributes[:convenio] = '234'
|
114
115
|
@valid_attributes[:conta_corrente] = '356156'
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
RSpec.describe Brcobranca::Boleto::BancoBrasil do
|
5
|
+
RSpec.describe Brcobranca::Boleto::BancoBrasil do # :nodoc:[all]
|
6
6
|
before do
|
7
7
|
@valid_attributes = {
|
8
8
|
valor: 0.0,
|
@@ -179,7 +179,9 @@ RSpec.describe Brcobranca::Boleto::BancoBrasil do #:nodoc:[all]
|
|
179
179
|
|
180
180
|
expect(boleto_novo.conta_corrente_dv).to be(0)
|
181
181
|
expect { boleto_novo.codigo_barras_segunda_parte }.to raise_error(RuntimeError)
|
182
|
-
expect
|
182
|
+
expect do
|
183
|
+
boleto_novo.codigo_barras_segunda_parte
|
184
|
+
end.to raise_error('Só é permitido emitir boletos com nosso número de 17 dígitos com carteiras 16 ou 18. Sua carteira atual é 17')
|
183
185
|
end
|
184
186
|
|
185
187
|
it 'Montar código de barras para convenio de 4 digitos e nosso numero de 7' do
|
@@ -301,15 +303,15 @@ RSpec.describe Brcobranca::Boleto::BancoBrasil do #:nodoc:[all]
|
|
301
303
|
@valid_attributes[:convenio] = 1_238_798
|
302
304
|
@valid_attributes[:nosso_numero] = '7777700168'
|
303
305
|
boleto_novo = described_class.new(@valid_attributes)
|
304
|
-
%w
|
306
|
+
%w[pdf jpg tif png].each do |format|
|
305
307
|
file_body = boleto_novo.send("to_#{format}".to_sym)
|
306
308
|
tmp_file = Tempfile.new(['foobar.', format])
|
307
309
|
tmp_file.puts file_body
|
308
310
|
tmp_file.close
|
309
|
-
expect(File.exist
|
310
|
-
expect(File.stat(tmp_file.path)
|
311
|
+
expect(File).to exist(tmp_file.path)
|
312
|
+
expect(File.stat(tmp_file.path)).not_to be_zero
|
311
313
|
expect(File.delete(tmp_file.path)).to be(1)
|
312
|
-
expect(File.exist
|
314
|
+
expect(File).not_to exist(tmp_file.path)
|
313
315
|
end
|
314
316
|
end
|
315
317
|
|
@@ -320,15 +322,15 @@ RSpec.describe Brcobranca::Boleto::BancoBrasil do #:nodoc:[all]
|
|
320
322
|
@valid_attributes[:convenio] = 1_238_798
|
321
323
|
@valid_attributes[:nosso_numero] = '7777700168'
|
322
324
|
boleto_novo = described_class.new(@valid_attributes)
|
323
|
-
%w
|
325
|
+
%w[pdf jpg tif png].each do |format|
|
324
326
|
file_body = boleto_novo.to(format)
|
325
327
|
tmp_file = Tempfile.new(['foobar.', format])
|
326
328
|
tmp_file.puts file_body
|
327
329
|
tmp_file.close
|
328
|
-
expect(File.exist
|
329
|
-
expect(File.stat(tmp_file.path)
|
330
|
+
expect(File).to exist(tmp_file.path)
|
331
|
+
expect(File.stat(tmp_file.path)).not_to be_zero
|
330
332
|
expect(File.delete(tmp_file.path)).to be(1)
|
331
|
-
expect(File.exist
|
333
|
+
expect(File).not_to exist(tmp_file.path)
|
332
334
|
end
|
333
335
|
end
|
334
336
|
end
|