Sha256: 43de56c1ffc9d014ccc3c467908673ed02a4336842cdcdfbab165edb2293cb66

Contents?: true

Size: 365 Bytes

Versions: 2

Compression:

Stored size: 365 Bytes

Contents

require 'russianpost/barcode/base'

module RussianPost
  module Barcode
    class Domestic < Base
      def self.format
        /\A\d{14}\Z/
      end

      private

      def checkdigit
        odds, evens = *digits.partition.with_index { |d, i| (i&1).zero? }
        (10 - ((odds.reduce(:+) * 3 + evens[0..-2].reduce(:+)) % 10)) % 10
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
russianpost-0.7.0 lib/russianpost/barcode/domestic.rb
russianpost-0.6.0 lib/russianpost/barcode/domestic.rb