brcobranca 9.2.4 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -9
  3. data/HISTORY.md +71 -0
  4. data/README.md +47 -54
  5. data/Rakefile +4 -4
  6. data/lib/brcobranca/arquivos/logos/ailos.eps +412 -0
  7. data/lib/brcobranca/arquivos/logos/ailos_carne.eps +412 -0
  8. data/lib/brcobranca/arquivos/logos/safra.eps +0 -0
  9. data/lib/brcobranca/arquivos/logos/safra_carne.eps +0 -0
  10. data/lib/brcobranca/boleto/{cecred.rb → ailos.rb} +7 -5
  11. data/lib/brcobranca/boleto/banco_brasil.rb +9 -5
  12. data/lib/brcobranca/boleto/banco_brasilia.rb +5 -5
  13. data/lib/brcobranca/boleto/banco_nordeste.rb +4 -3
  14. data/lib/brcobranca/boleto/banestes.rb +4 -3
  15. data/lib/brcobranca/boleto/banrisul.rb +4 -3
  16. data/lib/brcobranca/boleto/base.rb +12 -7
  17. data/lib/brcobranca/boleto/bradesco.rb +4 -3
  18. data/lib/brcobranca/boleto/caixa.rb +10 -8
  19. data/lib/brcobranca/boleto/citibank.rb +9 -8
  20. data/lib/brcobranca/boleto/credisis.rb +6 -4
  21. data/lib/brcobranca/boleto/hsbc.rb +8 -6
  22. data/lib/brcobranca/boleto/itau.rb +5 -5
  23. data/lib/brcobranca/boleto/safra.rb +4 -4
  24. data/lib/brcobranca/boleto/santander.rb +4 -2
  25. data/lib/brcobranca/boleto/sicoob.rb +4 -3
  26. data/lib/brcobranca/boleto/sicredi.rb +6 -3
  27. data/lib/brcobranca/boleto/template/base.rb +2 -3
  28. data/lib/brcobranca/boleto/template/rghost.rb +18 -13
  29. data/lib/brcobranca/boleto/template/rghost_carne.rb +18 -12
  30. data/lib/brcobranca/boleto/unicred.rb +61 -103
  31. data/lib/brcobranca/calculo.rb +14 -9
  32. data/lib/brcobranca/calculo_data.rb +6 -5
  33. data/lib/brcobranca/currency.rb +10 -10
  34. data/lib/brcobranca/formatacao.rb +2 -1
  35. data/lib/brcobranca/formatacao_string.rb +7 -6
  36. data/lib/brcobranca/limpeza.rb +3 -3
  37. data/lib/brcobranca/remessa/base.rb +7 -10
  38. data/lib/brcobranca/remessa/cnab240/{cecred.rb → ailos.rb} +18 -15
  39. data/lib/brcobranca/remessa/cnab240/banco_brasil.rb +14 -11
  40. data/lib/brcobranca/remessa/cnab240/base.rb +56 -39
  41. data/lib/brcobranca/remessa/cnab240/base_correspondente.rb +25 -17
  42. data/lib/brcobranca/remessa/cnab240/caixa.rb +21 -13
  43. data/lib/brcobranca/remessa/cnab240/sicoob.rb +33 -30
  44. data/lib/brcobranca/remessa/cnab240/sicoob_banco_brasil.rb +14 -7
  45. data/lib/brcobranca/remessa/cnab240/sicredi.rb +28 -22
  46. data/lib/brcobranca/remessa/cnab240/unicred.rb +2 -1
  47. data/lib/brcobranca/remessa/cnab400/banco_brasil.rb +9 -9
  48. data/lib/brcobranca/remessa/cnab400/banco_brasilia.rb +29 -28
  49. data/lib/brcobranca/remessa/cnab400/banco_nordeste.rb +11 -10
  50. data/lib/brcobranca/remessa/cnab400/banrisul.rb +13 -10
  51. data/lib/brcobranca/remessa/cnab400/base.rb +22 -9
  52. data/lib/brcobranca/remessa/cnab400/bradesco.rb +30 -5
  53. data/lib/brcobranca/remessa/cnab400/citibank.rb +6 -5
  54. data/lib/brcobranca/remessa/cnab400/credisis.rb +7 -5
  55. data/lib/brcobranca/remessa/cnab400/itau.rb +9 -6
  56. data/lib/brcobranca/remessa/cnab400/santander.rb +17 -15
  57. data/lib/brcobranca/remessa/cnab400/sicoob.rb +8 -11
  58. data/lib/brcobranca/remessa/cnab400/unicred.rb +185 -69
  59. data/lib/brcobranca/remessa/pagamento.rb +43 -11
  60. data/lib/brcobranca/retorno/base.rb +5 -43
  61. data/lib/brcobranca/retorno/cnab240/{cecred.rb → ailos.rb} +12 -10
  62. data/lib/brcobranca/retorno/cnab240/base.rb +8 -9
  63. data/lib/brcobranca/retorno/cnab240/caixa.rb +4 -5
  64. data/lib/brcobranca/retorno/cnab240/santander.rb +12 -8
  65. data/lib/brcobranca/retorno/cnab240/sicoob.rb +11 -9
  66. data/lib/brcobranca/retorno/cnab240/sicredi.rb +12 -9
  67. data/lib/brcobranca/retorno/cnab400/banco_brasil.rb +3 -3
  68. data/lib/brcobranca/retorno/cnab400/banco_brasilia.rb +2 -1
  69. data/lib/brcobranca/retorno/cnab400/banco_nordeste.rb +2 -1
  70. data/lib/brcobranca/retorno/cnab400/banrisul.rb +1 -1
  71. data/lib/brcobranca/retorno/cnab400/base.rb +13 -12
  72. data/lib/brcobranca/retorno/cnab400/bradesco.rb +4 -4
  73. data/lib/brcobranca/retorno/cnab400/credisis.rb +2 -1
  74. data/lib/brcobranca/retorno/cnab400/itau.rb +6 -5
  75. data/lib/brcobranca/retorno/cnab400/santander.rb +8 -7
  76. data/lib/brcobranca/retorno/cnab400/unicred.rb +63 -58
  77. data/lib/brcobranca/retorno/retorno_cbr643.rb +1 -2
  78. data/lib/brcobranca/retorno/retorno_cnab240.rb +11 -9
  79. data/lib/brcobranca/retorno/retorno_cnab400.rb +6 -5
  80. data/lib/brcobranca/util/date.rb +2 -1
  81. data/lib/brcobranca/util/empresa.rb +2 -1
  82. data/lib/brcobranca/util/errors.rb +31 -31
  83. data/lib/brcobranca/validations.rb +127 -151
  84. data/lib/brcobranca/version.rb +2 -3
  85. data/lib/brcobranca.rb +5 -5
  86. data/spec/brcobranca/base_spec.rb +20 -11
  87. data/spec/brcobranca/boleto/{cecred_spec.rb → ailos_spec.rb} +13 -12
  88. data/spec/brcobranca/boleto/banco_brasil_spec.rb +14 -12
  89. data/spec/brcobranca/boleto/banco_brasilia_spec.rb +11 -10
  90. data/spec/brcobranca/boleto/banco_nordeste_spec.rb +2 -3
  91. data/spec/brcobranca/boleto/banestes_spec.rb +10 -11
  92. data/spec/brcobranca/boleto/banrisul_spec.rb +10 -12
  93. data/spec/brcobranca/boleto/bradesco_spec.rb +36 -33
  94. data/spec/brcobranca/boleto/caixa_spec.rb +11 -12
  95. data/spec/brcobranca/boleto/citibank_spec.rb +10 -11
  96. data/spec/brcobranca/boleto/credisis_spec.rb +18 -17
  97. data/spec/brcobranca/boleto/hsbc_spec.rb +9 -10
  98. data/spec/brcobranca/boleto/itau_spec.rb +11 -12
  99. data/spec/brcobranca/boleto/safra_spec.rb +10 -11
  100. data/spec/brcobranca/boleto/santander_spec.rb +9 -10
  101. data/spec/brcobranca/boleto/sicoob_spec.rb +10 -11
  102. data/spec/brcobranca/boleto/sicredi_spec.rb +14 -10
  103. data/spec/brcobranca/boleto/unicred_spec.rb +28 -38
  104. data/spec/brcobranca/boletos_em_lote_spec.rb +7 -7
  105. data/spec/brcobranca/calculo_data_spec.rb +2 -2
  106. data/spec/brcobranca/calculo_spec.rb +13 -11
  107. data/spec/brcobranca/currency_spec.rb +26 -26
  108. data/spec/brcobranca/formatacao_spec.rb +2 -2
  109. data/spec/brcobranca/formatacao_string_spec.rb +10 -4
  110. data/spec/brcobranca/limpeza_spec.rb +2 -2
  111. data/spec/brcobranca/remessa/base_spec.rb +1 -2
  112. data/spec/brcobranca/remessa/cnab240/{cecred_spec.rb → ailos_spec.rb} +48 -47
  113. data/spec/brcobranca/remessa/cnab240/banco_brasil_spec.rb +18 -13
  114. data/spec/brcobranca/remessa/cnab240/base_spec.rb +33 -10
  115. data/spec/brcobranca/remessa/cnab240/caixa_spec.rb +19 -17
  116. data/spec/brcobranca/remessa/cnab240/sicoob_banco_brasil_spec.rb +12 -8
  117. data/spec/brcobranca/remessa/cnab240/sicoob_spec.rb +28 -26
  118. data/spec/brcobranca/remessa/cnab240/sicredi_spec.rb +12 -10
  119. data/spec/brcobranca/remessa/cnab240/unicred_spec.rb +11 -9
  120. data/spec/brcobranca/remessa/cnab400/banco_brasil_spec.rb +6 -3
  121. data/spec/brcobranca/remessa/cnab400/banco_brasilia_spec.rb +24 -19
  122. data/spec/brcobranca/remessa/cnab400/banco_nordeste_spec.rb +19 -14
  123. data/spec/brcobranca/remessa/cnab400/banrisul_spec.rb +17 -15
  124. data/spec/brcobranca/remessa/cnab400/base_spec.rb +23 -8
  125. data/spec/brcobranca/remessa/cnab400/bradesco_spec.rb +19 -17
  126. data/spec/brcobranca/remessa/cnab400/citibank_spec.rb +14 -12
  127. data/spec/brcobranca/remessa/cnab400/credisis_spec.rb +21 -19
  128. data/spec/brcobranca/remessa/cnab400/itau_spec.rb +18 -16
  129. data/spec/brcobranca/remessa/cnab400/santander_spec.rb +24 -22
  130. data/spec/brcobranca/remessa/cnab400/sicoob_spec.rb +20 -20
  131. data/spec/brcobranca/remessa/cnab400/unicred_spec.rb +167 -166
  132. data/spec/brcobranca/remessa/pagamento_spec.rb +16 -15
  133. data/spec/brcobranca/retorno/cnab240/base_spec.rb +10 -9
  134. data/spec/brcobranca/retorno/cnab240/cecred_spec.rb +4 -2
  135. data/spec/brcobranca/retorno/cnab240/santander_spec.rb +2 -0
  136. data/spec/brcobranca/retorno/cnab240/sicoob_spec.rb +2 -0
  137. data/spec/brcobranca/retorno/cnab240/sicredi_spec.rb +2 -0
  138. data/spec/brcobranca/retorno/cnab400/banco_brasilia_spec.rb +2 -1
  139. data/spec/brcobranca/retorno/cnab400/banco_nordeste_spec.rb +2 -1
  140. data/spec/brcobranca/retorno/cnab400/banrisul_spec.rb +2 -1
  141. data/spec/brcobranca/retorno/cnab400/base_spec.rb +25 -25
  142. data/spec/brcobranca/retorno/cnab400/bradesco_spec.rb +2 -1
  143. data/spec/brcobranca/retorno/cnab400/credisis_spec.rb +5 -4
  144. data/spec/brcobranca/retorno/cnab400/itau_spec.rb +4 -2
  145. data/spec/brcobranca/retorno/cnab400/santander_spec.rb +2 -1
  146. data/spec/brcobranca/retorno/cnab400/unicred_spec.rb +28 -32
  147. data/spec/brcobranca/retorno/retorno_cbr643_spec.rb +2 -2
  148. data/spec/brcobranca/retorno/retorno_cnab400_spec.rb +2 -1
  149. data/spec/brcobranca/retorno/retorno_cnab_240_spec.rb +2 -1
  150. data/spec/brcobranca/rghost_spec.rb +4 -4
  151. data/spec/brcobranca/util/empresa_spec.rb +1 -2
  152. data/spec/brcobranca_spec.rb +1 -2
  153. metadata +85 -162
  154. data/spec/arquivos/CBR64310.RET +0 -28
  155. data/spec/arquivos/CNAB240.RET +0 -74
  156. data/spec/arquivos/CNAB240CECRED.RET +0 -10
  157. data/spec/arquivos/CNAB240SANTANDER.RET +0 -8
  158. data/spec/arquivos/CNAB240SICOOB.RET +0 -10
  159. data/spec/arquivos/CNAB240SICREDI.CRT +0 -8
  160. data/spec/arquivos/CNAB400.RET +0 -54
  161. data/spec/arquivos/CNAB400BANCOBRASILIA.RET +0 -3
  162. data/spec/arquivos/CNAB400BANCONORDESTE.RET +0 -3
  163. data/spec/arquivos/CNAB400BANRISUL.RET +0 -3
  164. data/spec/arquivos/CNAB400BRADESCO.RET +0 -8
  165. data/spec/arquivos/CNAB400CREDISIS.RET +0 -3
  166. data/spec/arquivos/CNAB400ITAU.RET +0 -54
  167. data/spec/arquivos/CNAB400SANTANDER.RET +0 -54
  168. data/spec/arquivos/CNAB400UNICRED.RET +0 -3
  169. data/spec/fixtures/remessa/remessa-banco-brasil-cnab400.rem +0 -3
  170. data/spec/fixtures/remessa/remessa-banco-brasilia-cnab400.rem +0 -3
  171. data/spec/fixtures/remessa/remessa-banco-nordeste-cnab400.rem +0 -3
  172. data/spec/fixtures/remessa/remessa-banco_brasil-cnab240.rem +0 -7
  173. data/spec/fixtures/remessa/remessa-bancoob-cnab240.rem +0 -7
  174. data/spec/fixtures/remessa/remessa-banrisul-cnab400.rem +0 -3
  175. data/spec/fixtures/remessa/remessa-bradesco-cnab400.rem +0 -3
  176. data/spec/fixtures/remessa/remessa-caixa-cnab240.rem +0 -7
  177. data/spec/fixtures/remessa/remessa-cecred-cnab240.rem +0 -7
  178. data/spec/fixtures/remessa/remessa-citibank-cnab400.rem +0 -3
  179. data/spec/fixtures/remessa/remessa-credisis-cnab400.rem +0 -3
  180. data/spec/fixtures/remessa/remessa-itau-cnab400.rem +0 -4
  181. data/spec/fixtures/remessa/remessa-santander-cnab400.rem +0 -3
  182. data/spec/fixtures/remessa/remessa-sicoob-cnab400.rem +0 -3
  183. data/spec/fixtures/remessa/remessa-sicoob-correspondente-bb-cnab240.rem +0 -4
  184. data/spec/fixtures/remessa/remessa-sicredi-cnab240.rem +0 -7
  185. data/spec/fixtures/remessa/remessa-unicred-cnab240.rem +0 -7
  186. data/spec/fixtures/remessa/remessa-unicred-cnab400.rem +0 -3
  187. data/spec/spec.opts +0 -8
  188. data/spec/spec_helper.rb +0 -38
  189. data/spec/support/remessa_helpers.rb +0 -13
  190. data/spec/support/shared_examples/busca_logotipo.rb +0 -15
  191. data/spec/support/shared_examples/cnab240.rb +0 -259
  192. data/spec/support/shared_examples/cnab400.rb +0 -180
  193. 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 = [:if, :unless, :on, :allow_nil, :allow_blank, :strict]
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 :count :size
30
+ alias count size
30
31
 
31
- def generate_message(attribute, type = :invalid, options = {})
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 :to_a :full_messages
39
+ alias to_a full_messages
39
40
 
40
41
  private
41
42
 
42
- def apply_default_array(hash)
43
- hash.default_proc = proc { |h, key| h[key] = [] }
44
- hash
45
- end
43
+ def apply_default_array(hash)
44
+ hash.default_proc = proc { |h, key| h[key] = [] }
45
+ hash
46
+ end
46
47
 
47
- def normalize_message(attribute, message, options)
48
- case message
49
- when Symbol
50
- generate_message(attribute, message, except(options, *CALLBACKS_OPTIONS))
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
- if message.start_with?(variable_name(attribute))
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
- def normalize_detail(message, options)
61
- { error: message }.merge(except(options, *CALLBACKS_OPTIONS + MESSAGE_OPTIONS))
62
- end
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
- def variable_name(symbol)
71
- symbol.to_s.tr("_", " ").capitalize
72
- end
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
- # coding: utf-8
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 if !check_eachs
65
- all_valid = false if !check_presences
66
- all_valid = false if !check_numericals
67
- all_valid = false if !check_lengths
68
- all_valid = false if !check_inclusions
69
- return all_valid
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
- def check_eachs
79
- eachs = {}
80
- if self.class.superclass.superclass.respond_to?(:eachs)
81
- eachs.merge!(self.class.superclass.superclass.eachs || {})
82
- end
83
- if self.class.superclass.respond_to?(:eachs)
84
- eachs.merge!(self.class.superclass.eachs || {})
85
- end
86
- if self.class.eachs
87
- eachs.merge!(self.class.eachs)
88
- end
89
- return true if eachs.keys.size == 0
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
- return errors.size == 0
83
+ block.call(self, attr_name, value)
99
84
  end
85
+ errors.size.zero?
86
+ end
100
87
 
101
- def check_presences
102
- presences = []
103
- if self.class.superclass.superclass.respond_to?(:presences)
104
- presences = self.class.superclass.superclass.presences || []
105
- end
106
- if self.class.superclass.respond_to?(:presences)
107
- presences += self.class.superclass.presences || []
108
- end
109
- if self.class.presences
110
- presences += self.class.presences
111
- end
112
- all_present = true
113
- presences.each do |presence|
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
- def check_numericals
125
- numericals = []
126
- if self.class.superclass.respond_to?(:numericals)
127
- numericals = self.class.superclass.numericals || []
128
- end
129
- if self.class.numericals
130
- numericals += self.class.numericals
131
- end
132
- return true if !numericals
133
- all_numerical = true
134
- numericals.each do |numerical|
135
- numerical.select { |p| p.is_a? Symbol}.each do |variable|
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
- def check_lengths
146
- lengths = []
147
- if self.class.superclass.superclass.respond_to?(:lengths)
148
- lengths = self.class.superclass.superclass.lengths || []
149
- end
150
- if self.class.superclass.respond_to?(:lengths)
151
- lengths += self.class.superclass.lengths || []
152
- end
153
- if self.class.lengths
154
- lengths += self.class.lengths
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
- return true if !lengths
157
- all_checked = true
158
- lengths.each do |rule|
159
- variable = rule[0]
160
- next if !self.respond_to?(variable)
161
- value = self.send(variable)
162
- if rule[-1][:in]
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
- if rule[-1][:is]
172
- if !value
173
- all_checked = false
174
- errors.add variable, rule[-1][:message]
175
- elsif value.to_s.size != rule[-1][:is]
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
- if rule[-1][:minimum] && rule[-1][:maximum]
181
- if !value || value.size < rule[-1][:minimum] || value.size > rule[-1][:maximum]
182
- all_checked = false
183
- errors.add variable, rule[-1][:message]
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
- def check_inclusions
196
- inclusions = []
197
- if self.class.superclass.superclass.respond_to?(:inclusions)
198
- inclusions = self.class.superclass.superclass.inclusions || []
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
- def variable_name(symbol)
224
- symbol.to_s.tr("_", " ").capitalize
225
- end
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
- def blank?(obj)
228
- return obj !~ /\S/ if obj.is_a? String
229
- obj.respond_to?(:empty?) ? obj.empty? : !obj
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
@@ -1,6 +1,5 @@
1
- # -*- encoding: utf-8 -*-
2
- #
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Brcobranca
5
- VERSION = '9.2.4'
4
+ VERSION = '10.0.0'
6
5
  end
data/lib/brcobranca.rb CHANGED
@@ -1,5 +1,5 @@
1
- # -*- encoding: utf-8 -*-
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
- # -*- encoding: utf-8 -*-
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.valid?).to be_falsey
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.valid?).to be_truthy
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 { boleto_novo.codigo_barras_segunda_parte }.to raise_error(Brcobranca::NaoImplementado, 'Sobreescreva este método na classe referente ao banco que você esta criando')
146
- expect { boleto_novo.nosso_numero_boleto }.to raise_error(Brcobranca::NaoImplementado, 'Sobreescreva este método na classe referente ao banco que você esta criando')
147
- expect { boleto_novo.agencia_conta_boleto }.to raise_error(Brcobranca::NaoImplementado, 'Sobreescreva este método na classe referente ao banco que você esta criando')
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?(:lote)).to be_truthy
152
- expect(described_class.respond_to?(:to)).to be_truthy
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?(:lote)).to be_truthy
158
- expect(boleto_novo.respond_to?(:to)).to be_truthy
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
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
- RSpec.describe Brcobranca::Boleto::Cecred do #:nodoc:[all]
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: 'PAGÁVEL PREFERENCIALMENTE NAS COOPERATIVAS DO SISTEMA CECRED',
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 eql(1)
70
- expect(boleto_novo.valor).to eql(0.0)
71
- expect(boleto_novo.valor_documento).to eql(0.0)
72
- expect(boleto_novo.local_pagamento).to eql('PAGÁVEL PREFERENCIALMENTE NAS COOPERATIVAS DO SISTEMA CECRED')
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 eql(1)
87
- expect(boleto_novo.valor).to eql(0.0)
88
- expect(boleto_novo.valor_documento).to eql(0.0)
89
- expect(boleto_novo.local_pagamento).to eql('PAGÁVEL PREFERENCIALMENTE NAS COOPERATIVAS DO SISTEMA CECRED')
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 eql(9)
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
- # -*- encoding: utf-8 -*-
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Brcobranca::Boleto::BancoBrasil do #:nodoc:[all]
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 { boleto_novo.codigo_barras_segunda_parte }.to raise_error('Só é permitido emitir boletos com nosso número de 17 dígitos com carteiras 16 ou 18. Sua carteira atual é 17')
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(pdf jpg tif png).each do |format|
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?(tmp_file.path)).to be_truthy
310
- expect(File.stat(tmp_file.path).zero?).to be_falsey
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?(tmp_file.path)).to be_falsey
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(pdf jpg tif png).each do |format|
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?(tmp_file.path)).to be_truthy
329
- expect(File.stat(tmp_file.path).zero?).to be_falsey
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?(tmp_file.path)).to be_falsey
333
+ expect(File).not_to exist(tmp_file.path)
332
334
  end
333
335
  end
334
336
  end