module QRCreditorReference
implement Creditor Reference ISO 11649 generator
Constants
- PREFIX
Public Class Methods
create(reference)
click to toggle source
# File lib/qr-bills/qr-creditor-reference.rb, line 37 def self.create(reference) reference = reference.delete(' ') chars = reference.split('') if chars.size == 0 raise QRExceptions::INVALID_PARAMETERS + ": provided reference too short: must be at least one char" end # max 25 chars: 2 chars (RF) + 2 chars (check code) + 21 chars (reference) if chars.size > 21 raise QRExceptions::INVALID_PARAMETERS + ": provided reference too long: must be less than 21 chars" end reference_val = "" chars.each do |c| reference_val += get_char_value(c).to_s end # put RF+00 at the end to resolve check code reference_val += @char_values["R".to_sym].to_s + @char_values["F".to_sym].to_s + "00" # get check code # when performing the validation of the check code (n % 97) # the remainder must be equal to 1, thus the 98 check_code = 98 - (reference_val.to_i % 97) if check_code < 10 check_code = "0" + check_code.to_s end return PREFIX + check_code.to_s + reference end
get_char_value(char)
click to toggle source
# File lib/qr-bills/qr-creditor-reference.rb, line 71 def self.get_char_value(char) if char =~ /[0-9]/ return char.to_i end return @char_values[char.upcase.to_sym] end