lib/active_uxid/ulid.rb in active_uxid-1.0.10 vs lib/active_uxid/ulid.rb in active_uxid-1.0.11
- old
+ new
@@ -1,25 +1,18 @@
# frozen_string_literal: true
module ActiveUxid
- class Ulid
+ class Ulid < ActiveUxid::Base
- ENCODING_CHARS ||= ActiveUxid.configuration.encoding_chars
- ENCODING_LENGTH = ActiveUxid.configuration.encoding_length
-
- def initialize
- @encoding_length = ActiveUxid.configuration.encoding_length
- end
-
def self.encode
klass = new
klass.uxid_encode
end
def uxid_encode
- (1..@encoding_length).reduce('') do |str, num|
+ (1..encoding_length).reduce('') do |str, num|
shift = 128 - 5 * num
- "#{str}#{ENCODING_CHARS[(uxid_octect >> shift) & 0x1f]}"
+ "#{str}#{encoding_chars[(uxid_octect >> shift) & 0x1f]}"
end
end
def uxid_bytes
"#{uxid_unixtime_48bit}#{SecureRandom.random_bytes(10)}"