Class: MixinBot::Utils::UUID
- Inherits:
-
Object
- Object
- MixinBot::Utils::UUID
- Defined in:
- lib/mixin_bot/utils/uuid.rb
Instance Attribute Summary collapse
-
#hex ⇒ Object
Returns the value of attribute hex.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(**args) ⇒ UUID
constructor
A new instance of UUID.
- #packed ⇒ Object
- #unpacked ⇒ Object
Constructor Details
#initialize(**args) ⇒ UUID
Returns a new instance of UUID.
8 9 10 11 12 13 14 |
# File 'lib/mixin_bot/utils/uuid.rb', line 8 def initialize(**args) @hex = args[:hex] @raw = args[:raw] raise MixinBot::InvalidUuidFormatError if raw.present? && raw.size != 16 raise MixinBot::InvalidUuidFormatError if hex.present? && hex.gsub('-', '').size != 32 end |
Instance Attribute Details
#hex ⇒ Object
Returns the value of attribute hex.
6 7 8 |
# File 'lib/mixin_bot/utils/uuid.rb', line 6 def hex @hex end |
#raw ⇒ Object
Returns the value of attribute raw.
6 7 8 |
# File 'lib/mixin_bot/utils/uuid.rb', line 6 def raw @raw end |
Instance Method Details
#packed ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/mixin_bot/utils/uuid.rb', line 16 def packed if raw.present? raw elsif hex.present? [hex.gsub('-', '')].pack('H*') end end |
#unpacked ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mixin_bot/utils/uuid.rb', line 24 def unpacked _hex = if hex.present? hex.gsub('-', '') elsif raw.present? _hex = raw.unpack1('H*') end format( '%<first>s-%<second>s-%<third>s-%<forth>s-%<fifth>s', first: _hex[0..7], second: _hex[8..11], third: _hex[12..15], forth: _hex[16..19], fifth: _hex[20..] ) end |