Class: BrBoleto::Calculos::FatorVencimento

Inherits:
String
  • Object
show all
Defined in:
lib/br_boleto/calculos/fator_vencimento.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expiration_date, options = {}) ⇒ FatorVencimento

Returns a new instance of FatorVencimento.



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 96

def initialize(expiration_date, options={})
  @expiration_date = expiration_date
  self.base_date = options[:base_date]          
  self.subtracao = options[:subtracao]          
  self.soma      = options[:soma]     
  self.quantidade_de_caracteres   = options[:quantidade_de_caracteres]        

  if @expiration_date.present?
    super(calculate)
  end
end

Instance Attribute Details

#base_dateObject

A base é des de quando será subtraido a data de validade



51
52
53
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 51

def base_date
  @base_date
end

#quantidade_de_caracteresObject

Caso necessite modificar o número de caracteres de retorno



90
91
92
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 90

def quantidade_de_caracteres
  @quantidade_de_caracteres
end

#somaObject

Caso necessite somar o resultado entre a diferença do (vencimento - data_base)



84
85
86
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 84

def soma
  @soma
end

#subtracaoObject

Caso necessite subtratir o resultado entre a diferença do (vencimento - data_base)



77
78
79
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 77

def subtracao
  @subtracao
end

Instance Method Details

#calculateString

Cálculo da data de vencimento com a data base.

Returns:

  • (String)

    exatamente 4 dígitos



114
115
116
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 114

def calculate
  expiration_date_minus_base_date.to_s.rjust(quantidade_de_caracteres, '0')
end

#expiration_date_minus_base_dateInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cálculo da data de vencimento com a data base. Chamando #to_i para não retornar um Float.

Returns:

  • (Integer)

    diff between this two dates.



124
125
126
# File 'lib/br_boleto/calculos/fator_vencimento.rb', line 124

def expiration_date_minus_base_date
  ((@expiration_date - base_date).to_i+soma)-subtracao
end