Sha256: 8e4e215166fec955f155ef80050cb75e469419e2e1ee67855af26ef5a8a37b3d

Contents?: true

Size: 440 Bytes

Versions: 3

Compression:

Stored size: 440 Bytes

Contents

require "jan/parser"
require "jan/check_digit_calculator"

class Jan < ::String
  module Validator
    module_function

    def validate(code)
      validate_size(code.to_s) && validate_check_digit(code.to_s)
    end

    def validate_size(code)
      [8,13].include?(code.to_s.size)
    end

    def validate_check_digit(code)
      Parser.check_digit(code.to_s) == CheckDigitCalculator.calculate(Parser.body(code.to_s))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jan-0.1.0 lib/jan/validator.rb
jan-0.0.5 lib/jan/validator.rb
jan-0.0.4 lib/jan/validator.rb