Class: MixinBot::UUID
- Inherits:
-
Object
- Object
- MixinBot::UUID
- Defined in:
- lib/mixin_bot/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.
7 8 9 10 11 12 13 |
# File 'lib/mixin_bot/uuid.rb', line 7 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.
5 6 7 |
# File 'lib/mixin_bot/uuid.rb', line 5 def hex @hex end |
#raw ⇒ Object
Returns the value of attribute raw.
5 6 7 |
# File 'lib/mixin_bot/uuid.rb', line 5 def raw @raw end |
Instance Method Details
#packed ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/mixin_bot/uuid.rb', line 15 def packed if raw.present? raw elsif hex.present? [hex.gsub('-', '')].pack('H*') end end |
#unpacked ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mixin_bot/uuid.rb', line 23 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 |