123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- class Ldap
-
-
-
-
- class Guid
-
-
-
-
-
-
-
-
-
- def self.valid?(string)
- string.match?(%r{\w{8}-\w{4}-\w{4}-\w{4}-\w+})
- end
-
-
-
-
-
-
-
-
-
- def self.hex(string)
- new(string).hex
- end
-
-
-
-
-
-
-
-
-
- def self.string(hex)
- new(hex).string
- end
-
-
-
-
-
-
-
-
- def initialize(guid)
- @guid = guid
- end
-
-
-
-
-
-
-
- def hex
- [oracle_raw16(guid)].pack('H*')
- end
-
-
-
-
-
-
-
- def string
- oracle_raw16(guid.unpack1('H*'), dashify: true)
- end
- private
- attr_reader :guid
- def oracle_raw16(string, dashify: false)
-
- string.delete!('-')
-
- parts = string.scan(%r{.{1,2}})
-
- oracle_format_indices = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15]
- result = oracle_format_indices.map { |index| parts[index] }.join
-
- return result if !dashify
- [
- result[0..7],
- result[8..11],
- result[12..15],
- result[16..19],
- result[20..result.size]
- ].join('-')
- end
- end
- end
|