Class: BRDocuments::IE::Base

Inherits:
DigitChecksum::BaseDocument
  • Object
show all
Defined in:
lib/br_documents/documents/ie/base.rb

Constant Summary collapse

INITIAL_FIX_NUMBERS_POSITION =

Start from first position

0
FIXED_INITIAL_NUMBERS =

No one

[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fixed_digitsObject



59
60
61
# File 'lib/br_documents/documents/ie/base.rb', line 59

def fixed_digits
  self.const_get('FIXED_INITIAL_NUMBERS')
end

.fixed_digits_positionsObject



55
56
57
# File 'lib/br_documents/documents/ie/base.rb', line 55

def fixed_digits_positions
  self.const_get('INITIAL_FIX_NUMBERS_POSITION')
end

.generate_root_numbersObject



45
46
47
48
49
50
51
52
53
# File 'lib/br_documents/documents/ie/base.rb', line 45

def generate_root_numbers
  numbers = (root_digits_count - fixed_digits.size).times.map {
    get_generator_numbers.sample.to_i
  }

  append_fixed_digits(numbers)

  numbers
end

.set_fixed_digits(initial_numbers) ⇒ Object



63
64
65
# File 'lib/br_documents/documents/ie/base.rb', line 63

def set_fixed_digits(initial_numbers)
  self.const_set('FIXED_INITIAL_NUMBERS', initial_numbers).freeze
end

.valid_fixed_digits?(number) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/br_documents/documents/ie/base.rb', line 36

def valid_fixed_digits?(number)
  number = new(number).normalize

  initial_pos = fixed_digits_positions
  fixed_numbers = fixed_digits

  return (number.slice(initial_pos, fixed_numbers.size) == fixed_numbers)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/br_documents/documents/ie/base.rb', line 19

def valid?
  return false unless valid_fixed_digits?

  return super
end

#valid_fixed_digits?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/br_documents/documents/ie/base.rb', line 25

def valid_fixed_digits?
  return true unless validate_fixed_digits?

  self.class.valid_fixed_digits?(self.number)
end

#validate_fixed_digits?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/br_documents/documents/ie/base.rb', line 31

def validate_fixed_digits?
  true
end