https://github.com/sage/guid_spanner
Packs, unpacks and converts 32 and 36 bit and binary uuids
https://github.com/sage/guid_spanner
Last synced: about 1 year ago
JSON representation
Packs, unpacks and converts 32 and 36 bit and binary uuids
- Host: GitHub
- URL: https://github.com/sage/guid_spanner
- Owner: Sage
- License: apache-2.0
- Archived: true
- Created: 2017-08-25T06:51:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-22T13:18:51.000Z (almost 8 years ago)
- Last Synced: 2025-03-12T21:28:11.328Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 18
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# guid_spanner
[](https://travis-ci.org/Sage/guid_spanner)
[](https://codeclimate.com/github/Sage/guid_spanner/maintainability)
[](https://codeclimate.com/github/Sage/guid_spanner/test_coverage)
[](http://badge.fury.io/rb/guid_spanner)
Packs and unpacks 32(compact) and 36 charactor GUIDs
# Install
```ruby
require 'guid_spanner'
```
```ruby
bundle
```
# Usage
## Unpack a 32 GUID to 36
```ruby
GuidSpanner::Guid.unpack_to_36('1be7eaa5aba341e895a653e66be98fef')
=> '1be7eaa5-aba3-41e8-95a6-53e66be98fef'
```
## Pack a 36 char GUID to 32
```ruby
GuidSpanner::Guid.pack_to_32('1be7eaa5-aba3-41e8-95a6-53e66be98fef')
=> '1be7eaa5aba341e895a653e66be98fef'
```
## Convert a 36 char GUID to binary
```ruby
GuidSpanner::Guid.str_to_bin('1be7eaa5-aba3-41e8-95a6-53e66be98fef')
=> '\e\xE7\xEA\xA5\xAB\xA3A\xE8\x95\xA6S\xE6k\xE9\x8F\xEF'
```
## Convert a binary GUID to 36 char
```ruby
GuidSpanner::Guid.bin_to_str('\e\xE7\xEA\xA5\xAB\xA3A\xE8\x95\xA6S\xE6k\xE9\x8F\xEF')
=> '1be7eaa5-aba3-41e8-95a6-53e66be98fef'
```
# Exceptions
Raises
```ruby
GuidSpanner::Exceptions::InvalidUuidFormatError
```
if an incorrectly formatted GUID is provided for packing or unpacking or conversion
## Licence
Guid Spanner is licensed under the [Apache-2.0 licence](https://github.com/Sage/guid_spanner/blob/master/LICENSE).
Copyright (c) 2018 Sage Group Plc. All rights reserved.