Sha256: 02ecc7535baf477005245c933237d995aa292c982b8b07e5bebf6f3db54d64ab

Contents?: true

Size: 526 Bytes

Versions: 1

Compression:

Stored size: 526 Bytes

Contents

require 'jan/code_body'
require 'jan/check_digit'

module Jan
  class Code < String
    # @param code [String]
    def initialize(code)
      @body = Jan::CodeBody.new(code[0..-2])
      @check_digit = Jan::CheckDigit.new(code[-1])
      super(code)
    end

    attr_reader :body, :check_digit

    # @return [boolean]
    def valid?
      @body.valid? && @check_digit.valid? && @body.calculate_check_digit == @check_digit
    end

    # @return [boolean]
    def instore_code?
      @body.start_with?('2')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jan-0.2.0 lib/jan/code.rb