### Installation Source: https://context7.com/sporkmonger/uuidtools/llms.txt Instructions on how to install the UUIDTools gem. ```APIDOC ## Installation Install the UUIDTools gem from RubyGems to add UUID generation capabilities to your Ruby application. ```ruby # Install via gem gem install uuidtools # Or add to Gemfile gem 'uuidtools', '~> 3.0' ``` ``` -------------------------------- ### Install UUIDTools Gem Source: https://github.com/sporkmonger/uuidtools/blob/main/README.md Use this command to install the UUIDTools gem on your system. ```bash $ sudo gem install uuidtools ``` -------------------------------- ### Install UUIDTools Gem Source: https://context7.com/sporkmonger/uuidtools/llms.txt Install the UUIDTools gem using RubyGems or add it to your Gemfile for use in your Ruby application. ```ruby gem install uuidtools ``` ```ruby gem 'uuidtools', '~> 3.0' ``` -------------------------------- ### Generate MD5 UUID (v3) Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a version 3 UUID deterministically using an MD5 hash from a namespace UUID and a name string. This ensures that the same namespace and name will always produce the same UUID. The example shows generation using the DNS namespace and demonstrates that identical inputs yield identical UUIDs. It also lists available namespaces. ```ruby require 'uuidtools' # Generate MD5-based UUID using DNS namespace uuid = UUIDTools::UUID.md5_create( UUIDTools::UUID_DNS_NAMESPACE, "www.example.com" ) # => # uuid.to_s # => "5df41881-3aed-3515-88a7-2f4a814cf09e" uuid.version # => 3 uuid.valid? # => true # Same input always produces same UUID uuid1 = UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "test.com") uuid2 = UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "test.com") uuid1 == uuid2 # => true # Using URL namespace for URL-based identifiers url_uuid = UUIDTools::UUID.md5_create( UUIDTools::UUID_URL_NAMESPACE, "http://sporkmonger.com" ) url_uuid.to_s # => "15074785-9071-3fe3-89bd-876e4b9e919b" # Available namespaces UUIDTools::UUID_DNS_NAMESPACE # For domain names UUIDTools::UUID_URL_NAMESPACE # For URLs UUIDTools::UUID_OID_NAMESPACE # For OIDs UUIDTools::UUID_X500_NAMESPACE # For X.500 DNs ``` -------------------------------- ### Generate SHA1 UUID (v5) Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a version 5 UUID deterministically using a SHA1 hash from a namespace UUID and a name string. This is preferred over MD5 for new applications due to stronger cryptographic properties. The example shows generation using the DNS and URL namespaces, and highlights that the same input consistently produces the same UUID. ```ruby require 'uuidtools' # Generate SHA1-based UUID using DNS namespace uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com" ) # => # uuid.to_s # => "21f7f8de-8051-5b89-8680-0195ef798b6a" uuid.version # => 5 uuid.valid? # => true # Using URL namespace url_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_URL_NAMESPACE, "http://sporkmonger.com" ) url_uuid.to_s # => "f2d04685-b787-55da-8644-9bd28a6f5a53" # Deterministic generation - useful for consistent IDs across systems user_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_URL_NAMESPACE, "user:alice@example.com" ) # Always generates same UUID for same input ``` -------------------------------- ### Generate UUIDs with UUIDTools Source: https://github.com/sporkmonger/uuidtools/blob/main/README.md Demonstrates how to generate different types of UUIDs using the UUIDTools library. Requires 'require "uuidtools"' to be present. ```ruby require "uuidtools" UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com") # => # ``` ```ruby UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com") # => # ``` ```ruby UUIDTools::UUID.timestamp_create # => # ``` ```ruby UUIDTools::UUID.random_create # => # ``` -------------------------------- ### UUID.md5_create Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a deterministic UUID (version 3) using MD5 hash from a namespace UUID and a name string. ```APIDOC ## UUID.md5_create Creates a deterministic UUID (version 3) using MD5 hash from a namespace UUID and a name string. Same namespace and name always produce the same UUID, making this useful for generating reproducible identifiers. ```ruby require 'uuidtools' # Generate MD5-based UUID using DNS namespace uuid = UUIDTools::UUID.md5_create( UUIDTools::UUID_DNS_NAMESPACE, "www.example.com" ) # => # uuid.to_s # => "5df41881-3aed-3515-88a7-2f4a814cf09e" uuid.version # => 3 uuid.valid? # => true # Same input always produces same UUID uuid1 = UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "test.com") uuid2 = UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "test.com") uuid1 == uuid2 # => true # Using URL namespace for URL-based identifiers url_uuid = UUIDTools::UUID.md5_create( UUIDTools::UUID_URL_NAMESPACE, "http://sporkmonger.com" ) url_uuid.to_s # => "15074785-9071-3fe3-89bd-876e4b9e919b" # Available namespaces UUIDTools::UUID_DNS_NAMESPACE # For domain names UUIDTools::UUID_URL_NAMESPACE # For URLs UUIDTools::UUID_OID_NAMESPACE # For OIDs UUIDTools::UUID_X500_NAMESPACE # For X.500 DNs ``` ``` -------------------------------- ### UUID.sha1_create Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a deterministic UUID (version 5) using SHA1 hash from a namespace UUID and a name string. ```APIDOC ## UUID.sha1_create Creates a deterministic UUID (version 5) using SHA1 hash from a namespace UUID and a name string. Preferred over MD5 for new applications due to stronger cryptographic properties. Same namespace and name always produce the same UUID. ```ruby require 'uuidtools' # Generate SHA1-based UUID using DNS namespace uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_DNS_NAMESPACE, "www.widgets.com" ) # => # uuid.to_s # => "21f7f8de-8051-5b89-8680-0195ef798b6a" uuid.version # => 5 uuid.valid? # => true # Using URL namespace url_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_URL_NAMESPACE, "http://sporkmonger.com" ) url_uuid.to_s # => "f2d04685-b787-55da-8644-9bd28a6f5a53" # Deterministic generation - useful for consistent IDs across systems user_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_URL_NAMESPACE, "user:alice@example.com" ) # Always generates same UUID for same input ``` ``` -------------------------------- ### Generate Timestamp UUID (v1) Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a version 1 UUID using the current timestamp and MAC address. If no MAC address is available, a random node ID is used. This snippet demonstrates generating a UUID with the current time, extracting its timestamp and MAC address, and checking if a random node ID was used. It also shows how to generate a UUID for a specific timestamp. ```ruby require 'uuidtools' # Generate timestamp-based UUID with current time uuid = UUIDTools::UUID.timestamp_create # => # uuid.to_s # => "64a5189c-25b3-11da-a97b-00c04fd430c8" uuid.version # => 1 uuid.valid? # => true # Extract timestamp from UUID uuid.timestamp # => 2024-01-15 10:30:45 UTC # Get MAC address embedded in UUID (if system has one) uuid.mac_address # => "00:c0:4f:d4:30:c8" or nil if random node # Check if UUID uses random node ID (no MAC available) uuid.random_node_id? # => false (if MAC was used) or true (if random) # Generate UUID for specific timestamp specific_time = Time.utc(2024, 6, 15, 12, 0, 0) uuid = UUIDTools::UUID.timestamp_create(specific_time) uuid.timestamp # => 2024-06-15 12:00:00 UTC ``` -------------------------------- ### Generate Different UUID Versions Source: https://context7.com/sporkmonger/uuidtools/llms.txt Create UUIDs using different generation strategies: random, timestamp-based, MD5-based, and SHA1-based. Each method returns a UUID object with a specific version. ```ruby require 'uuidtools' random_uuid = UUIDTools::UUID.random_create random_uuid.version # => 4 timestamp_uuid = UUIDTools::UUID.timestamp_create timestamp_uuid.version # => 1 md5_uuid = UUIDTools::UUID.md5_create(UUIDTools::UUID_DNS_NAMESPACE, "test") md5_uuid.version # => 3 sha1_uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "test") sha1_uuid.version # => 5 ``` -------------------------------- ### UUID Comparison and Sorting Source: https://context7.com/sporkmonger/uuidtools/llms.txt Compare UUIDs for equality and ordering. UUIDs implement the Comparable module, allowing them to be used in sorted collections and as hash keys. ```ruby require 'uuidtools' # Equality comparison uuid1 = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") uuid2 = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") uuid3 = UUIDTools::UUID.random_create uuid1 == uuid2 # => true uuid1.eql?(uuid2) # => true uuid1 == uuid3 # => false # Ordering comparison small = UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]) large = UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 1]) small < large # => true large > small # => true # Sorting timestamp UUIDs (chronological order) uuids = 10.times.map { UUIDTools::UUID.timestamp_create } sorted = uuids.sort sorted.first < sorted.last # => true # Using UUIDs as hash keys cache = {} key = UUIDTools::UUID.random_create cache[key] = "value" cache[key] # => "value" ``` -------------------------------- ### Predefined Namespace Constants for Name-Based UUIDs Source: https://context7.com/sporkmonger/uuidtools/llms.txt Utilize predefined namespace UUIDs (DNS, URL, OID, X.500) from RFC 4122 to generate deterministic name-based UUIDs using SHA1 hashing. ```ruby require 'uuidtools' # DNS namespace - for fully qualified domain names UUIDTools::UUID_DNS_NAMESPACE.to_s # => "6ba7b810-9dad-11d1-80b4-00c04fd430c8" dns_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_DNS_NAMESPACE, "example.com" ) # URL namespace - for URLs UUIDTools::UUID_URL_NAMESPACE.to_s # => "6ba7b811-9dad-11d1-80b4-00c04fd430c8" url_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_URL_NAMESPACE, "https://example.com/resource" ) # OID namespace - for ISO OIDs UUIDTools::UUID_OID_NAMESPACE.to_s # => "6ba7b812-9dad-11d1-80b4-00c04fd430c8" oid_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_OID_NAMESPACE, "1.3.6.1.4.1.343" ) # X.500 namespace - for X.500 Distinguished Names UUIDTools::UUID_X500_NAMESPACE.to_s # => "6ba7b814-9dad-11d1-80b4-00c04fd430c8" x500_uuid = UUIDTools::UUID.sha1_create( UUIDTools::UUID_X500_NAMESPACE, "cn=John Doe,ou=People,dc=example,dc=com" ) ``` -------------------------------- ### UUID.timestamp_create Source: https://context7.com/sporkmonger/uuidtools/llms.txt Creates a time-based UUID (version 1) using the current timestamp and MAC address. ```APIDOC ## UUID.timestamp_create Creates a time-based UUID (version 1) using the current timestamp and MAC address. When no MAC address is available, a random node ID is generated. Optionally accepts a specific timestamp for deterministic UUID generation. ```ruby require 'uuidtools' # Generate timestamp-based UUID with current time uuid = UUIDTools::UUID.timestamp_create # => # uuid.to_s # => "64a5189c-25b3-11da-a97b-00c04fd430c8" uuid.version # => 1 uuid.valid? # => true # Extract timestamp from UUID uuid.timestamp # => 2024-01-15 10:30:45 UTC # Get MAC address embedded in UUID (if system has one) uuid.mac_address # => "00:c0:4f:d4:30:c8" or nil if random node # Check if UUID uses random node ID (no MAC available) uuid.random_node_id? # => false (if MAC was used) or true (if random) # Generate UUID for specific timestamp specific_time = Time.utc(2024, 6, 15, 12, 0, 0) uuid = UUIDTools::UUID.timestamp_create(specific_time) uuid.timestamp # => 2024-06-15 12:00:00 UTC ``` ``` -------------------------------- ### UUID Properties and Validation Source: https://context7.com/sporkmonger/uuidtools/llms.txt UUID objects provide methods to inspect their version, variant, validity, and other properties. ```APIDOC ## UUID Properties and Validation UUIDs provide methods to inspect their version, variant, validity, and other properties. These methods help identify UUID types and validate parsed UUIDs. ### Method - `uuid.version` - `uuid.variant` - `uuid.valid?` - `uuid.nil_uuid?` ### Request Example ```ruby require 'uuidtools' # Check UUID version uuid_v4 = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") puts uuid_v4.version # => 4 uuid_v7 = UUIDTools::UUID.parse("01957ca6-fc1a-7322-956e-e9e6c53cab55") puts uuid_v7.version # => 7 # Check validity puts uuid_v4.valid? # => true # Check if it's a nil UUID nil_uuid = UUIDTools::UUID.parse("00000000-0000-0000-0000-000000000000") puts nil_uuid.nil_uuid? # => true ``` ### Response #### Success Response (200) - **version** (Integer) - The version of the UUID (e.g., 1, 3, 4, 5, 7). - **variant** (Integer) - The variant of the UUID (e.g., 0 for NCS backward compatibility, 2 for RFC 4122). - **valid?** (Boolean) - Returns `true` if the UUID is valid, `false` otherwise. - **nil_uuid?** (Boolean) - Returns `true` if the UUID is the nil UUID, `false` otherwise. #### Response Example ``` 4 7 true true ``` ``` -------------------------------- ### Generate Random UUID (v4) Source: https://context7.com/sporkmonger/uuidtools/llms.txt Generates a version 4 UUID using cryptographically secure random bytes. This is suitable when no specific timestamp or namespace is required. It also shows how to convert the UUID object to its string representation and check its properties. ```ruby require 'uuidtools' # Generate a random UUID uuid = UUIDTools::UUID.random_create # => # # Convert to string representation uuid.to_s # => "984265dc-4200-4f02-ae70-fe4f48964159" # Check UUID properties uuid.version # => 4 uuid.valid? # => true uuid.nil_uuid? # => false # Generate multiple unique UUIDs uuids = 100.times.map { UUIDTools::UUID.random_create.to_s } uuids.uniq.size # => 100 (all unique) ``` -------------------------------- ### UUID.random_create Source: https://context7.com/sporkmonger/uuidtools/llms.txt Generates a random UUID (version 4) using cryptographically secure random bytes. ```APIDOC ## UUID.random_create Generates a random UUID (version 4) using cryptographically secure random bytes. This is the simplest method for generating unique identifiers when no specific timestamp or namespace requirements exist. ```ruby require 'uuidtools' # Generate a random UUID uuid = UUIDTools::UUID.random_create # => # # Convert to string representation uuid.to_s # => "984265dc-4200-4f02-ae70-fe4f48964159" # Check UUID properties uuid.version # => 4 uuid.valid? # => true uuid.nil_uuid? # => false # Generate multiple unique UUIDs uuids = 100.times.map { UUIDTools::UUID.random_create.to_s } uuids.uniq.size # => 100 (all unique) ``` ``` -------------------------------- ### Check UUID Variant and Validity Source: https://context7.com/sporkmonger/uuidtools/llms.txt Determine the variant of a UUID (e.g., RFC 4122 compliant) and validate if it conforms to RFC 4122 standards. Also, check for the nil UUID. ```ruby # Check UUID variant (RFC 4122 compliant UUIDs return 0b100) random_uuid.variant # => 4 (0b100) # Validate UUID conforms to RFC 4122 random_uuid.valid? # => true UUIDTools::UUID.parse("01957ca6-fc1a-7322-956e-e9e6c53cab55").valid? # => true (v7) # Check for nil UUID nil_uuid = UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]) nil_uuid.nil_uuid? # => true nil_uuid.valid? # => false random_uuid.nil_uuid? # => false ``` -------------------------------- ### Parse UUID from Raw Bytes Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from raw 16-byte binary data. Useful for reading UUIDs stored in binary format. Short input is padded with leading zeros. ```ruby require 'uuidtools' # Parse UUID from raw bytes raw_bytes = "\xf4\x7a\xc1\x0b\x58\xcc\x43\x72\xa5\x67\x0e\x02\xb2\xc3\xd4\x79" uuid = UUIDTools::UUID.parse_raw(raw_bytes) uuid.to_s # => "f47ac10b-58cc-4372-a567-0e02b2c3d479" # Round-trip: UUID -> raw -> UUID original = UUIDTools::UUID.random_create raw = original.raw parsed = UUIDTools::UUID.parse_raw(raw) original == parsed # => true # Parse nil UUID from empty/null bytes nil_uuid = UUIDTools::UUID.parse_raw("\0" * 16) nil_uuid.nil_uuid? # => true # Short input is padded with leading zeros short_raw = "\x01\x02\x03" uuid = UUIDTools::UUID.parse_raw(short_raw) ``` -------------------------------- ### Convert UUID to Various Output Formats Source: https://context7.com/sporkmonger/uuidtools/llms.txt UUID objects can be converted to multiple output formats including standard string, raw bytes, 128-bit integer, 32-character hexdigest, and URN representation. ```ruby require 'uuidtools' uuid = UUIDTools::UUID.random_create # Standard string representation (8-4-4-4-12 format) uuid.to_s # => "984265dc-4200-4f02-ae70-fe4f48964159" # Also available as to_str for implicit string conversion "UUID: #{uuid}" # => "UUID: 984265dc-4200-4f02-ae70-fe4f48964159" # Raw 16-byte binary representation uuid.raw # => "\x98Be\xDCB\x00O\x02\xAEp\xFEOH\x96AY" uuid.raw.bytesize # => 16 # 128-bit integer representation uuid.to_i # => 202170692055684583904687608814731542873 # 32-character hexadecimal digest (no dashes) uuid.hexdigest # => "984265dc42004f02ae70fe4f48964159" # URN format for URI systems uuid.to_uri # => "urn:uuid:984265dc-4200-4f02-ae70-fe4f48964159" # Integer hash for use in hash tables uuid.hash # => 878542313 ``` -------------------------------- ### MAC Address Handling in UUIDs Source: https://context7.com/sporkmonger/uuidtools/llms.txt Manage MAC addresses for time-based UUIDs. The system's MAC address is auto-detected, but can be manually set for testing or specific environments. You can also check if a UUID uses a random node ID. ```ruby require 'uuidtools' # Get system MAC address UUIDTools::UUID.mac_address # => "00:c0:4f:d4:30:c8" or nil if unavailable # Manually set MAC address (useful for testing or containers) UUIDTools::UUID.mac_address = "aa:bb:cc:dd:ee:ff" uuid = UUIDTools::UUID.timestamp_create uuid.mac_address # => "aa:bb:cc:dd:ee:ff" # Check if UUID uses random node ID UUIDTools::UUID.mac_address = nil uuid_random_node = UUIDTools::UUID.timestamp_create uuid_random_node.random_node_id? # => true uuid_random_node.mac_address # => nil # Restore MAC detection UUIDTools::UUID.mac_address = UUIDTools::UUID.mac_address uuid_real_mac = UUIDTools::UUID.timestamp_create uuid_real_mac.random_node_id? # => false (if system has MAC) # Extract MAC from parsed timestamp UUID parsed = UUIDTools::UUID.parse("64a5189c-25b3-11da-a97b-00c04fd430c8") parsed.mac_address # => "00:c0:4f:d4:30:c8" (if version 1 with real MAC) ``` -------------------------------- ### UUID Output Formats Source: https://context7.com/sporkmonger/uuidtools/llms.txt UUID objects can be converted into various formats including string, raw bytes, integer, hexdigest, and URN. ```APIDOC ## UUID Output Formats UUIDs can be converted to multiple output formats for different use cases including string, raw bytes, integer, hexdigest, and URN representations. ### Method - `uuid.to_s` - `uuid.raw` - `uuid.to_i` - `uuid.hexdigest` - `uuid.to_uri` - `uuid.hash` ### Request Example ```ruby require 'uuidtools' uuid = UUIDTools::UUID.random_create # Standard string representation (8-4-4-4-12 format) puts uuid.to_s # Raw 16-byte binary representation puts uuid.raw # 128-bit integer representation puts uuid.to_i # 32-character hexadecimal digest (no dashes) puts uuid.hexdigest # URN format for URI systems puts uuid.to_uri # Integer hash for use in hash tables puts uuid.hash ``` ### Response #### Success Response (200) - **string**: Standard UUID string format. - **raw**: 16-byte binary representation. - **integer**: 128-bit integer representation. - **hexdigest**: 32-character hexadecimal string. - **uri**: URN format string. - **hash**: Integer hash value. #### Response Example ``` 984265dc-4200-4f02-ae70-fe4f48964159 "\x98Be\xDCB\x00O\x02\xAEp\xFEOH\x96AY" 202170692055684583904687608814731542873 984265dc42004f02ae70fe4f48964159 urn:uuid:984265dc-4200-4f02-ae70-fe4f48964159 878542313 ``` ``` -------------------------------- ### UUID.parse_raw Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from 16-byte raw binary data. This is useful for reading UUIDs stored in binary formats. ```APIDOC ## UUID.parse_raw Parses a UUID from raw 16-byte binary data. Useful for reading UUIDs stored in binary format in databases or binary protocols. ### Method `UUIDTools::UUID.parse_raw(raw_bytes)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby require 'uuidtools' # Parse UUID from raw bytes raw_bytes = "\xf4\x7a\xc1\x0b\x58\xcc\x43\x72\xa5\x67\x0e\x02\xb2\xc3\xd4\x79" uuid = UUIDTools::UUID.parse_raw(raw_bytes) puts uuid.to_s # Nil UUID from empty/null bytes nil_uuid = UUIDTools::UUID.parse_raw("\0" * 16) puts nil_uuid.nil_uuid? # Short input is padded with leading zeros short_raw = "\x01\x02\x03" uuid = UUIDTools::UUID.parse_raw(short_raw) puts uuid.to_s ``` ### Response #### Success Response (200) - **uuid** (UUID) - A UUID object representing the parsed UUID. #### Response Example ``` f47ac10b-58cc-4372-a567-0e02b2c3d479 true 01020300-0000-0000-0000-000000000000 ``` ``` -------------------------------- ### UUID.parse Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from its standard string representation (8-4-4-4-12 hexadecimal format). It handles case-insensitivity and raises an ArgumentError for invalid UUID strings. ```APIDOC ## UUID.parse Parses a UUID from its standard string representation (8-4-4-4-12 hexadecimal format). Raises ArgumentError for invalid UUID strings. ### Method `UUIDTools::UUID.parse(uuid_string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby require 'uuidtools' # Parse standard UUID string uuid = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") puts uuid.to_s # Handle invalid UUID strings begin UUIDTools::UUID.parse("invalid-uuid-string") rescue ArgumentError => e puts e.message end ``` ### Response #### Success Response (200) - **uuid** (UUID) - A UUID object representing the parsed UUID. #### Response Example ``` # ``` ### Error Handling - **ArgumentError**: Raised if the input string is not a valid UUID format. ``` -------------------------------- ### Parse UUID from Integer Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from its 128-bit integer representation. Useful for storing UUIDs as numbers. The nil UUID is represented by zero. ```ruby require 'uuidtools' # Parse UUID from integer integer_value = 324378908082322875023488665317731192953 uuid = UUIDTools::UUID.parse_int(integer_value) uuid.to_s # => "f47ac10b-58cc-4372-a567-0e02b2c3d479" # Round-trip: UUID -> integer -> UUID original = UUIDTools::UUID.random_create int_value = original.to_i parsed = UUIDTools::UUID.parse_int(int_value) original == parsed # => true # Nil UUID from zero nil_uuid = UUIDTools::UUID.parse_int(0) nil_uuid.nil_uuid? # => true nil_uuid.to_s # => "00000000-0000-0000-0000-000000000000" # Integer representation useful for database storage uuid = UUIDTools::UUID.timestamp_create db_value = uuid.to_i # Store as BIGINT or NUMERIC ``` -------------------------------- ### Parse UUID from Hexdigest Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from a 32-character hexadecimal string without dashes. Useful for compact UUID storage. The nil UUID hexdigest is all zeros. ```ruby require 'uuidtools' # Parse UUID from hexdigest (no dashes) hexdigest = "f47ac10b58cc4372a5670e02b2c3d479" uuid = UUIDTools::UUID.parse_hexdigest(hexdigest) uuid.to_s # => "f47ac10b-58cc-4372-a567-0e02b2c3d479" # Round-trip: UUID -> hexdigest -> UUID original = UUIDTools::UUID.timestamp_create hex = original.hexdigest # => "64a5189c25b311daa97b00c04fd430c8" parsed = UUIDTools::UUID.parse_hexdigest(hex) original == parsed # => true # Hexdigest is always 32 characters uuid = UUIDTools::UUID.random_create uuid.hexdigest.size # => 32 # Nil UUID hexdigest nil_uuid = UUIDTools::UUID.parse_hexdigest("00000000000000000000000000000000") nil_uuid.nil_uuid? # => true ``` -------------------------------- ### Parse UUID from Standard String Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from its standard string representation (8-4-4-4-12 hexadecimal format). Raises ArgumentError for invalid UUID strings. Supports case-insensitive parsing. ```ruby require 'uuidtools' # Parse standard UUID string uuid = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") # => # uuid.to_s # => "f47ac10b-58cc-4372-a567-0e02b2c3d479" uuid.version # => 4 uuid.valid? # => true # Parse and inspect a v7 UUID v7_uuid = UUIDTools::UUID.parse("01957ca6-fc1a-7322-956e-e9e6c53cab55") v7_uuid.valid? # => true v7_uuid.version # => 7 # Handle invalid UUID strings begin UUIDTools::UUID.parse("invalid-uuid-string") rescue ArgumentError => e puts e.message # => "Invalid UUID format." end # Case-insensitive parsing uuid1 = UUIDTools::UUID.parse("F47AC10B-58CC-4372-A567-0E02B2C3D479") uuid2 = UUIDTools::UUID.parse("f47ac10b-58cc-4372-a567-0e02b2c3d479") uuid1 == uuid2 # => true ``` -------------------------------- ### UUID.parse_int Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from its 128-bit integer representation. This is useful for storing UUIDs as numbers. ```APIDOC ## UUID.parse_int Parses a UUID from its 128-bit integer representation. Useful for storing UUIDs as numbers in databases or performing numeric operations. ### Method `UUIDTools::UUID.parse_int(integer_value)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby require 'uuidtools' # Parse UUID from integer integer_value = 324378908082322875023488665317731192953 uuid = UUIDTools::UUID.parse_int(integer_value) puts uuid.to_s # Nil UUID from zero nil_uuid = UUIDTools::UUID.parse_int(0) puts nil_uuid.nil_uuid? puts nil_uuid.to_s ``` ### Response #### Success Response (200) - **uuid** (UUID) - A UUID object representing the parsed UUID. #### Response Example ``` f47ac10b-58cc-4372-a567-0e02b2c3d479 true 00000000-0000-0000-0000-000000000000 ``` ``` -------------------------------- ### UUID.parse_hexdigest Source: https://context7.com/sporkmonger/uuidtools/llms.txt Parses a UUID from a 32-character hexadecimal string without dashes. This is useful for compact UUID storage. ```APIDOC ## UUID.parse_hexdigest Parses a UUID from a 32-character hexadecimal string without dashes. Useful for compact UUID storage or parsing UUIDs from systems that omit dashes. ### Method `UUIDTools::UUID.parse_hexdigest(hexdigest_string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```ruby require 'uuidtools' # Parse UUID from hexdigest (no dashes) hexdigest = "f47ac10b58cc4372a5670e02b2c3d479" uuid = UUIDTools::UUID.parse_hexdigest(hexdigest) puts uuid.to_s # Nil UUID hexdigest nil_uuid = UUIDTools::UUID.parse_hexdigest("00000000000000000000000000000000") puts nil_uuid.nil_uuid? ``` ### Response #### Success Response (200) - **uuid** (UUID) - A UUID object representing the parsed UUID. #### Response Example ``` f47ac10b-58cc-4372-a567-0e02b2c3d479 true ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.