lib/active_uxid/ulid.rb in active_uxid-1.0.9 vs lib/active_uxid/ulid.rb in active_uxid-1.0.10
- old
+ new
@@ -4,18 +4,20 @@
class Ulid
ENCODING_CHARS ||= ActiveUxid.configuration.encoding_chars
ENCODING_LENGTH = ActiveUxid.configuration.encoding_length
- def initialize; end
+ 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]}"
end
end