Class: Valideez::Regon

Inherits:
Base
  • Object
show all
Includes:
Common
Defined in:
lib/valideez/regon.rb

Instance Attribute Summary

Attributes inherited from Base

#val, #validable

Instance Method Summary collapse

Methods included from Common

#validate_format, #validate_length

Methods inherited from Base

#valid?

Constructor Details

#initialize(val, options = {}) ⇒ Regon

Returns a new instance of Regon.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/valideez/regon.rb', line 5

def initialize(val, options = {})
  super val

  assign({ 
    :format => /\A(\d{9}|\d{14})\Z/,
    :length => [9, 14],
    :mask => [8, 9, 2, 3, 4, 5, 6, 7],
    :mask_long => [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8],
    :modulo => 11,
    :sum_control => true,
  }.merge(options))

  @arr = []
end

Instance Method Details

#is_long?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/valideez/regon.rb', line 20

def is_long?
  val.size === 14
end

#validate_sum_controlObject



24
25
26
27
# File 'lib/valideez/regon.rb', line 24

def validate_sum_control
  mod = checksum % modulo
  mod === @arr.shift
end