class SAN
Public Class Methods
complete(six_digit_san)
click to toggle source
Purely for generating new SAN
numbers
# File lib/san.rb 49 def self.complete(six_digit_san) 50 six_digit_san = six_digit_san.to_s 51 return nil unless six_digit_san.length == 6 && six_digit_san.match(/\d{6}/) 52 53 arr = (0..5).to_a.collect { |i| six_digit_san[i,1].to_i * (7-i) } 54 sum = arr.inject { |sum, n| sum + n } 55 check = 11 - (sum % 11) 56 57 check = 0 if check == 11 58 check = 'X' if check == 10 59 60 six_digit_san + check.to_s 61 end
new(str)
click to toggle source
# File lib/san.rb 13 def initialize(str) 14 @number = str.to_s 15 end
valid?(san)
click to toggle source
# File lib/san.rb 43 def self.valid?(san) 44 san = san.to_s 45 san.length == 7 && san == SAN.complete(san[0,6]) 46 end
Public Instance Methods
to_uk_gln()
click to toggle source
convert this SAN
into a UK based Global Location Number.
see:
- http://en.wikipedia.org/wiki/Global_Location_Number - http://www.bisg.org/conferences/UConnnect_2007.pdf
# File lib/san.rb 38 def to_uk_gln 39 return nil unless valid? 40 EAN13.complete("503067#{@number[0,6]}") 41 end
to_us_gln()
click to toggle source
convert this SAN
into a US based Global Location Number.
see:
- http://en.wikipedia.org/wiki/Global_Location_Number - http://www.bisg.org/conferences/UConnnect_2007.pdf
# File lib/san.rb 27 def to_us_gln 28 return nil unless valid? 29 EAN13.complete("079999#{@number[0,6]}") 30 end
valid?()
click to toggle source
# File lib/san.rb 17 def valid? 18 SAN.valid? @number 19 end