Class: Guid
Overview
Guid - Ruby library for portable GUID/UUID generation.
Copyright © 2004 David Garamond <davegaramond at icqmail com>
This library is free software; you can redistribute it and/or modify it under the same terms as Ruby itself.
Constant Summary
Constants included
from Guid_Win32_
Guid_Win32_::CRYPT_VERIFYCONTEXT, Guid_Win32_::CryptAcquireContext, Guid_Win32_::CryptGenRandom, Guid_Win32_::CryptReleaseContext, Guid_Win32_::FORMAT_MESSAGE_FROM_SYSTEM, Guid_Win32_::FORMAT_MESSAGE_IGNORE_INSERTS, Guid_Win32_::FormatMessageA, Guid_Win32_::GetLastError, Guid_Win32_::PROV_RSA_FULL
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Guid_Unix_
#initialize
#initialize, #lastErrorMessage
Class Method Details
.from_raw(bytes) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/guid.rb', line 114
def self.from_raw(bytes)
raise ArgumentError, "Invalid GUID raw bytes, length must be 16 bytes" unless
bytes.length == 16
guid = Guid.allocate
guid.instance_eval { @bytes = bytes }
guid
end
|
.from_s(s) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/guid.rb', line 106
def self.from_s(s)
raise ArgumentError, "Invalid GUID hexstring" unless
s =~ /\A[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}\z/i
guid = Guid.allocate
guid.instance_eval { @bytes = [s.gsub(/[^0-9a-f]+/i, '')].pack "h*" }
guid
end
|
.win32? ⇒ Boolean
12
13
14
|
# File 'lib/guid.rb', line 12
def win32?
RUBY_PLATFORM =~ /[^r]win/i
end
|
Instance Method Details
#==(other) ⇒ Object
122
123
124
|
# File 'lib/guid.rb', line 122
def ==(other)
@bytes == other.raw
end
|
#hexdigest ⇒ Object
90
91
92
|
# File 'lib/guid.rb', line 90
def hexdigest
@bytes.unpack("h*")[0]
end
|
#inspect ⇒ Object
98
99
100
|
# File 'lib/guid.rb', line 98
def inspect
to_s
end
|
#raw ⇒ Object
102
103
104
|
# File 'lib/guid.rb', line 102
def raw
@bytes
end
|
#to_s ⇒ Object
94
95
96
|
# File 'lib/guid.rb', line 94
def to_s
@bytes.unpack("h8 h4 h4 h4 h12").join "-"
end
|