Module: ShortUUID
- Defined in:
- lib/shortuuid.rb,
lib/shortuuid/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
- .expand(short_uuid, alphabet = Radix::BASE::B62) ⇒ Object
- .shorten(uuid, alphabet = Radix::BASE::B62) ⇒ Object
Class Method Details
.expand(short_uuid, alphabet = Radix::BASE::B62) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shortuuid.rb', line 10 def self.(short_uuid, alphabet = Radix::BASE::B62) return nil unless short_uuid && !short_uuid.empty? uuid = short_uuid.b(alphabet).to_i.to_s(16).rjust(32, '0') [ uuid[0..7], uuid[8..11], uuid[12..15], uuid[16..19], uuid[20..31] ].join('-') end |
.shorten(uuid, alphabet = Radix::BASE::B62) ⇒ Object
5 6 7 8 |
# File 'lib/shortuuid.rb', line 5 def self.shorten(uuid, alphabet = Radix::BASE::B62) return nil unless uuid && !uuid.empty? uuid.split('-').join.to_i(16).b(10).to_s(alphabet) end |