Class: SAN
- Inherits:
-
Object
- Object
- SAN
- Defined in:
- lib/san.rb
Defined Under Namespace
Classes: Version
Class Method Summary collapse
-
.complete(six_digit_san) ⇒ Object
Purely for generating new SAN numbers.
- .valid?(san) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(str) ⇒ SAN
constructor
A new instance of SAN.
-
#to_uk_gln ⇒ Object
convert this SAN into a UK based Global Location Number.
-
#to_us_gln ⇒ Object
convert this SAN into a US based Global Location Number.
- #valid? ⇒ Boolean
Constructor Details
#initialize(str) ⇒ SAN
Returns a new instance of SAN.
13 14 15 |
# File 'lib/san.rb', line 13 def initialize(str) @number = str.to_s end |
Class Method Details
.complete(six_digit_san) ⇒ Object
Purely for generating new SAN numbers
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/san.rb', line 49 def self.complete(six_digit_san) six_digit_san = six_digit_san.to_s return nil unless six_digit_san.length == 6 && six_digit_san.match(/\d{6}/) #sum = (0..5).to_a.sum { |i| six_digit_san[i,1].to_i * (7-i) } arr = (0..5).to_a.collect { |i| six_digit_san[i,1].to_i * (7-i) } sum = arr.inject { |sum, n| sum + n } check = 11 - (sum % 11) check = 0 if check == 11 check = 'X' if check == 10 six_digit_san + check.to_s end |
Instance Method Details
#to_uk_gln ⇒ Object
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
38 39 40 41 |
# File 'lib/san.rb', line 38 def to_uk_gln return nil unless valid? EAN13.complete("503067#{@number[0,6]}") end |
#to_us_gln ⇒ Object
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
27 28 29 30 |
# File 'lib/san.rb', line 27 def to_us_gln return nil unless valid? EAN13.complete("079999#{@number[0,6]}") end |