Sha256: 9617d43e2ad9642444edf888d3dc5e8f767cb1dcb913859f4bf00aba4ada1112

Contents?: true

Size: 374 Bytes

Versions: 2

Compression:

Stored size: 374 Bytes

Contents

class Mod10 < LuhnBase
  def initialize number, options = {}
    super number, :base => [2, 1], :mod => 10
  end

  def check_digit
    10 - (sum % 10) 
  end

  private
  def before_sum base, number
    super(base, number).to_s.chars.map(&:to_i).reduce(:+)
  end
end

class String
  def mod10 digits = 1, options = {}
    (Mod10.new(self, options) * digits).to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brid-0.2.1 lib/brid/algorithms/mod10.rb
brid-0.2.0 lib/brid/algorithms/mod10.rb