Class: CommonNumbers::Polish::Nip
- Defined in:
- lib/common_numbers/nip.rb
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.
7 8 9 10 11 12 13 14 |
# File 'lib/common_numbers/nip.rb', line 7 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
20 21 22 |
# File 'lib/common_numbers/nip.rb', line 20 def international? /^PL/ =~ @magick_number end |
#validate_length ⇒ Object
16 17 18 |
# File 'lib/common_numbers/nip.rb', line 16 def validate_length @magick_number.size == (international? ? 12 : 10) end |
#validate_sum_control ⇒ Object
24 25 26 27 28 |
# File 'lib/common_numbers/nip.rb', line 24 def validate_sum_control magick_number.slice!(0..1) if international? mod = checksum % modulo mod === magick_array.shift end |