Class: Valvat::Checksum::GB

Inherits:
Base
  • Object
show all
Defined in:
lib/valvat/checksum/gb.rb

Constant Summary collapse

OLD_FORMAT_FORBIDDEN_RANGES =
[(100_000..999_999), (9_490_001..9_700_000), (9_990_001..9_999_999)].freeze
NEW_FORMAT_FORBIDDEN_RANGES =
[(1..100_000), (100_001..1_000_000)].freeze
GOV_NUMBER =
/\A(GD[0-4]{1}\d{2})\Z/.freeze
HEALTH_NUMBER =
/\A(HA[5-9]{1}\d{2})\Z/.freeze

Instance Attribute Summary

Attributes inherited from Base

#vat

Instance Method Summary collapse

Methods inherited from Base

check_digit_length, #initialize

Constructor Details

This class inherits a constructor from Valvat::Checksum::Base

Instance Method Details

#validateObject

rubocop:disable Metrics/CyclomaticComplexity



11
12
13
14
15
16
17
18
19
20
# File 'lib/valvat/checksum/gb.rb', line 11

def validate # rubocop:disable Metrics/CyclomaticComplexity
  # government departments and health authorities, so no checksum
  return true if gov_or_health?
  return false if all_zero?

  return false if old_format_remainder.zero? && fobidden_in_old_format?
  return false if new_format_remainder.zero? && fobidden_in_new_format?

  old_format_remainder.zero? || new_format_remainder.zero?
end