class BankOCR::AccountNumber

Object representing an account number

Public Class Methods

new(digits) click to toggle source
# File lib/account_number.rb, line 5
def initialize(digits)
  @digits = digits
end

Public Instance Methods

to_s() click to toggle source
# File lib/account_number.rb, line 13
def to_s
  @digits.map(&:value).join
end
valid?() click to toggle source
# File lib/account_number.rb, line 9
def valid?
  @valid ||= sum(to_s) % 11 == 0
end

Private Instance Methods

sum(account_number) click to toggle source
# File lib/account_number.rb, line 19
def sum(account_number)
  (0..8).map { |i| account_number[i].to_i * (i + 2) }.reduce(:+)
end