module ULID
Constants
- VERSION
Public Class Methods
Get a string ULID
encoding the given time.
@param at_time [Time] the time to encode @return [String] new ULID
string encoding the given time
@example Generate
a ULID
string for a given time
ULID.at(Time.at(1_000_000)) #=> 0009A0QS00SGEFTGMFFEAS6B9A
# File lib/ulid.rb, line 45 def self.at(at_time) Identifier.new(at_time).ulid end
Get the first possible ULID
string for the given time in sort order descending.
@param at_time [Time] a Time value to encode in the ULID
@return [String] the lexicographically maximum ULID
value for the given time
@example Get minimal ULID
at time
ULID.max_ulid_at Time.at(1_000_000) #=> "0009A0QS00ZZZZZZZZZZZZZZZZ"
# File lib/ulid.rb, line 81 def self.max_ulid_at(at_time) Identifier.new(at_time, MAX_ENTROPY).ulid end
Get the first possible ULID
string for the given time in sort order ascending.
@param at_time [Time] a Time value to encode in the ULID
@return [String] the lexicographically minimum ULID
value for the given time
@example Get minimal ULID
at time
ULID.min_ulid_at Time.at(1_000_000) #=> "0009A0QS000000000000000000"
# File lib/ulid.rb, line 69 def self.min_ulid_at(at_time) Identifier.new(at_time, MIN_ENTROPY).ulid end
Get a new, randomized ULID::Identifier
instance at the current time.
@return [ULID::Identifier] new ULID::Identifier
instance for the current system time
ULID.new #=> #<ULID::Identifier:0x007f83f90aecc0 ....>
# File lib/ulid.rb, line 22 def self.new(*args) Identifier.new(*args) end
Get the Time value encoded by the given ULID
string.
@param ulid [String or ULID::Identifier] @return [Time] UTC time value encoded by the ULID
@example Parse
a ULID
string and get a time value
ULID.time '0009A0QS00SGEFTGMFFEAS6B9A' #=> 1970-01-12 13:46:40 UTC
# File lib/ulid.rb, line 57 def self.time(ulid) Identifier.new(ulid).time.utc end