Module: SpaceCadetSpaceId
- Included in:
- SpaceCadetUuid
- Defined in:
- lib/space_cadet_space_id.rb
Instance Method Summary collapse
- #high_order_bits_from_hex_string(hex_string, bit_count) ⇒ Object
- #low_order_bits_from_hex_string(hex_string, bit_count) ⇒ Object
- #num_from_hex_string(hex_string) ⇒ Object
- #space_id_from_uuid(uuid, id_bit_count) ⇒ Object
Instance Method Details
#high_order_bits_from_hex_string(hex_string, bit_count) ⇒ Object
13 14 15 16 17 |
# File 'lib/space_cadet_space_id.rb', line 13 def high_order_bits_from_hex_string hex_string, bit_count total_bit_count = hex_string.length << 2 num = num_from_hex_string hex_string num >> (total_bit_count - bit_count) end |
#low_order_bits_from_hex_string(hex_string, bit_count) ⇒ Object
19 20 21 22 |
# File 'lib/space_cadet_space_id.rb', line 19 def low_order_bits_from_hex_string hex_string, bit_count num = num_from_hex_string hex_string num & ((1 << bit_count) - 1) end |
#num_from_hex_string(hex_string) ⇒ Object
9 10 11 |
# File 'lib/space_cadet_space_id.rb', line 9 def num_from_hex_string hex_string hex_string.bytes.reduce(0, &->(num,b){num <<= 4;num += HEX_DIGIT[b]}) end |
#space_id_from_uuid(uuid, id_bit_count) ⇒ Object
24 25 26 27 |
# File 'lib/space_cadet_space_id.rb', line 24 def space_id_from_uuid uuid, id_bit_count hex_string = uuid[24..-1] low_order_bits_from_hex_string hex_string, id_bit_count end |