Sha256: 144868ba118b82014832b16adf5a310f61e2f020c75fc97f978589d0c1b4e972

Contents?: true

Size: 822 Bytes

Versions: 1

Compression:

Stored size: 822 Bytes

Contents

require "codecal/version"

module Codecal
  def self.bank_customer_code_generate(account_id, currency)
    begin
      raise "parameter 1 type should be Integer and length less than 9" unless account_id.is_a?(Integer) && account_id.to_s.size <= 9
      raise "parameter 2 type should be Integer and length less than 4" unless currency.is_a?(Integer) && currency.to_s.size <= 4
      cal_array = ("%09d" % account_id + "%03d" % currency).split("").map! {|i| i.to_i}
      generate_seed = [2,7,5,3,8,9,5,9,1,6,7,3,5]
      return code_calculate(cal_array, generate_seed)
    rescue Exception => e
      puts e.message
    end
  end

  private
  def self.code_calculate(array, seed)
    code = array.each_with_index.inject(0){|count, (i, index)| count += i*seed[index]}
    return array.join + ("%03d" % code).to_s
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codecal-0.1.2 lib/codecal.rb