Coder Social home page Coder Social logo

ruby-ulid's Introduction

ruby-ulid

Build Status Gem Version

A handy ULID library

The ULID spec is defined on https://github.com/ulid/spec. Formal name is Universally Unique Lexicographically Sortable Identifier.

Install

$ gem install ruby-ulid

Usage

The generated ULID is an object rather than just a string. It means easily get the timestamps and binary formats.

require 'ulid'

ulid = ULID.generate #=> ULID(2021-04-27 17:27:22.826 UTC: 01F4A5Y1YAQCYAYCTC7GRMJ9AA)
ulid.to_time #=> 2021-04-27 17:27:22.826 UTC
ulid.to_s #=> "01F4A5Y1YAQCYAYCTC7GRMJ9AA"
ulid.octets #=> [1, 121, 20, 95, 7, 202, 187, 60, 175, 51, 76, 60, 49, 73, 37, 74]

You can parse from exists IDs

ulid = ULID.parse('01ARZ3NDEKTSV4RRFFQ69G5FAV') #=> ULID(2016-07-30 23:54:10.259 UTC: 01ARZ3NDEKTSV4RRFFQ69G5FAV)

Providing monotonic generator. It is called as Monotonicity on the spec.

ulids = 10000.times.map do
  ULID.generate
end
ulids.sort == ulids #=> false

monotonic_ulids = 10000.times.map do
  ULID.monotonic_generate
end
monotonic_ulids.sort == monotonic_ulids #=> true

Development

At first, you should install development dependencies

$ bundle install

Easy to play with the behaviors in REPL.

$ bin/console

If you try to add features, please ensure exist test cases are not broken

$ bundle exec rake test

If you try to improve any performance issue, please check the result of benchmarking before and after.

$ bundle exec ruby benchmark/*

Link

Author

Kenichi Kamiya - @kachick

ruby-ulid's People

Contributors

kachick avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.