ulid 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35d2c6d18033ca770195f08291137b3c7c1a433e
4
- data.tar.gz: 07c9bd33cdb6539399b113aa1c098547ff99c6bc
3
+ metadata.gz: 9a2e09c0725c50d9cdce66e66ca46f2c7fbdcf5b
4
+ data.tar.gz: 203d9b4b4c466561af9733512d1b3c118e77b851
5
5
  SHA512:
6
- metadata.gz: f1816b4b5a9b0fa787ce6e955aa11725471fd0c461864bba02036de42fbc12731d7dd7054bce4f444ab57ee8d3434dd7fd0e16d43c90ba1e5f4bdf986cafc196
7
- data.tar.gz: 804c088f3c1ddabc0d58741ef8baa9a4ead09778334581d9260b14b0028dc106f5a3eb4c9337328d603da9580e5af4b16415b6d1ea3bc26dbaff7c8ebce6250b
6
+ metadata.gz: e94a295f1b71498c1c21381f99e9b3ec888ba2a51acee99618985eecc35f6e94eff14baae6a459c54088bea252833ba0a11ff66f9b663fb9ac4a614b1260a52f
7
+ data.tar.gz: fc48c4ab0975c5d4a72d36c013bef2ebf3910574d42f2cea42a0e781ca7cfb6b3f60bff217e79b110bfcf38edc7f1dccd5c8e3520c460c6fb73432a8e3851658
data/Gemfile CHANGED
@@ -1,10 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in capistrano-pg_sync.gemspec
4
3
  gemspec
5
4
 
6
5
  group :development, :test do
7
- gem "bundler", "~> 1.12.5"
8
6
  gem "rake", "~> 10.0"
9
7
  gem "pry-byebug"
10
8
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ulid (0.0.1)
4
+ ulid (0.0.2)
5
5
  sysrandom (>= 1.0.0, < 2.0)
6
6
 
7
7
  GEM
@@ -29,7 +29,6 @@ PLATFORMS
29
29
  ruby
30
30
 
31
31
  DEPENDENCIES
32
- bundler (~> 1.12.5)
33
32
  minitest
34
33
  mocha
35
34
  pry-byebug
data/README.md CHANGED
@@ -42,7 +42,7 @@ gem install ulid
42
42
  ```ruby
43
43
  require 'ulid'
44
44
 
45
- ULID.generate // 01ARZ3NDEKTSV4RRFFQ69G5FAV
45
+ ULID.generate # 01ARZ3NDEKTSV4RRFFQ69G5FAV
46
46
  ```
47
47
 
48
48
  ## Specification
@@ -105,23 +105,10 @@ r is Randomness
105
105
  ## Test Suite
106
106
 
107
107
  ```
108
- # TODO
108
+ bundle exec rake test
109
109
  ```
110
110
 
111
- ## Performance
111
+ ### Credits and references:
112
112
 
113
- ```
114
- # TODO
115
- ```
116
-
117
- ```
118
- ulid
119
- 336,331,131 op/s » encodeTime
120
- 102,041,736 op/s » encodeRandom
121
- 17,408 op/s » generate
122
-
123
-
124
- Suites: 1
125
- Benches: 3
126
- Elapsed: 7,285.75 ms
127
- ```
113
+ * https://github.com/alizain/ulid
114
+ * https://github.com/ulid-org/spec
@@ -2,21 +2,23 @@ require 'sysrandom'
2
2
 
3
3
  module ULID
4
4
  class Generator
5
- ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
5
+ ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ' # Crockford's Base32
6
+ TIME_LENGTH = 10
7
+ RANDOM_LENGTH = 16
6
8
 
7
9
  def generate
8
- encode_time(milliseconds_since_epoch, 10) + encode_random(16)
10
+ encode_time(milliseconds_since_epoch, TIME_LENGTH) + encode_random(RANDOM_LENGTH)
9
11
  end
10
12
 
11
13
  private
12
14
 
13
15
  def encode_time(now, length)
14
- length.times.reduce("") do |output|
16
+ length.times.reduce('') do |output|
15
17
  mod = now % ENCODING.length
16
18
  now = (now - mod) / ENCODING.length
17
19
 
18
20
  output << ENCODING[mod]
19
- end
21
+ end.reverse
20
22
  end
21
23
 
22
24
  def encode_random(length)
@@ -24,7 +26,7 @@ module ULID
24
26
  random = Sysrandom.random_number(ENCODING.length)
25
27
 
26
28
  output << ENCODING[random]
27
- end
29
+ end.reverse
28
30
  end
29
31
 
30
32
  def milliseconds_since_epoch
data/lib/ulid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ULID
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,9 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ULID do
4
- it "works" do
4
+ it "ensures it has 26 chars" do
5
5
  ulid = ULID.generate
6
+
6
7
  ulid.length.must_equal 26
7
8
  end
9
+
10
+ it "is sortable" do
11
+ ulid_1 = ULID.generate
12
+ ulid_2 = ULID.generate
13
+
14
+ assert ulid_2 > ulid_1
15
+ end
8
16
  end
9
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ulid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Sales
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-02 00:00:00.000000000 Z
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sysrandom