module Subledger::UUID
Constants
- CHARS
- SPACE
- VALID
Public Class Methods
as_bignum()
click to toggle source
# File lib/subledger/uuid.rb, line 24 def self.as_bignum SecureRandom.random_number SPACE end
as_string()
click to toggle source
# File lib/subledger/uuid.rb, line 20 def self.as_string to_string as_bignum end
invalid?(uuid)
click to toggle source
# File lib/subledger/uuid.rb, line 16 def self.invalid? uuid uuid.nil? or uuid !~ VALID end
to_bignum(uuid)
click to toggle source
# File lib/subledger/uuid.rb, line 39 def self.to_bignum uuid bignum = 0 power = 0 uuid.split('').reverse.each do |character| bignum += CHARS.index( character ) * ( 62 ** power ) power += 1 end bignum end
to_string(bignum)
click to toggle source
# File lib/subledger/uuid.rb, line 28 def self.to_string bignum base_62 = '' 22.times do base_62 << CHARS[ bignum.modulo 62 ] bignum /= 62 end base_62.reverse end
valid?(uuid)
click to toggle source
# File lib/subledger/uuid.rb, line 12 def self.valid? uuid !uuid.nil? and uuid =~ VALID end