Class: MagickNumbers::Nip
Instance Attribute Summary
Attributes inherited from Base
#length, #magick_array, #magick_number, #mask, #modulo, #regexp
Instance Method Summary collapse
-
#initialize(num) ⇒ Nip
constructor
A new instance of Nip.
- #international? ⇒ Boolean
- #validate_length ⇒ Object
- #validate_sum_control ⇒ Object
Methods inherited from Base
#checksum, #valid?, #validate, #validate_regexp
Constructor Details
#initialize(num) ⇒ Nip
Returns a new instance of Nip.
5 6 7 8 9 10 11 12 |
# File 'lib/magick_numbers/nip.rb', line 5 def initialize(num) super(num) @mask = [ 6, 5, 7, 2, 3, 4, 5, 6, 7] @modulo = 11 @regexp = /^(PL)?[0-9]*/ # @magick_number = num.to_s.gsub('-', '') end |
Instance Method Details
#international? ⇒ Boolean
18 19 20 |
# File 'lib/magick_numbers/nip.rb', line 18 def international? /^PL/ =~ @magick_number end |
#validate_length ⇒ Object
14 15 16 |
# File 'lib/magick_numbers/nip.rb', line 14 def validate_length @magick_number.size == (international? ? 12 : 10) end |
#validate_sum_control ⇒ Object
22 23 24 25 26 |
# File 'lib/magick_numbers/nip.rb', line 22 def validate_sum_control magick_number.slice!(0..1) if international? mod = checksum % modulo mod === magick_array.shift end |