propertybase_id 0.3.0 → 0.3.1

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: 1333ef678322fc89dfff3adc990624e6f17c25de
4
- data.tar.gz: 44f789d27adb46ce42b3a90e667f6dd7dc193f8c
3
+ metadata.gz: 8174a759027e2fe2cde7b921fcbba58dabf1b75e
4
+ data.tar.gz: 513a4d715a43013d3c4049faf5acd0cef2730196
5
5
  SHA512:
6
- metadata.gz: 36b54a8284b3341635c8ff522c5eb667f7b8361ba4017168b8fc33dd371eb0d2803328bcf451b9f734b211abfedfda02175167f5b76755c209fde471bd813314
7
- data.tar.gz: f5582927e52d8f718a06e82bec071678f89c102a87be5d11e5e63cbb299ea1c08d8255c1ff6f4d13fa40b586febfea81aeb0ae3810dbbfdba7f3639b0e733fbb
6
+ metadata.gz: 5414790145e96bcc98829cf2c91a71cc229507c6ea1e96f3a3807e2f6e76f04e247a566fdc6dfb4266be28e4e7148004c63c23f537e4dca856099607133a88cb
7
+ data.tar.gz: 80698f1416d7f7fedc79ef9a3884ffbc0a47f89c0fdc0bb2cc9e93b3a39a576ff314e619e7d487943d1d5422b8c672cde4d2a0946323c24ce9e8aa8bf3062bcc
@@ -29,19 +29,15 @@ class PropertybaseId
29
29
  end
30
30
 
31
31
  def host_id
32
- @_host_id ||= Digest::SHA1.hexdigest(Socket.gethostname).to_i(16) % max_value(2)
32
+ @_host_id ||= Digest::SHA1.hexdigest(Socket.gethostname).to_i(16) % PropertybaseId.max_value(2)
33
33
  end
34
34
 
35
35
  def next_counter
36
- @counter = (@counter + 1) % max_value(5)
36
+ @counter = (@counter + 1) % PropertybaseId.max_value(5)
37
37
  end
38
38
 
39
39
  def process_id
40
- "#{Process.pid}#{Thread.current.object_id}".hash % max_value(2)
41
- end
42
-
43
- def max_value(digits)
44
- ("z" * digits).to_i(36) + 1
40
+ "#{Process.pid}#{Thread.current.object_id}".hash % PropertybaseId.max_value(2)
45
41
  end
46
42
  end
47
43
  end
@@ -1,3 +1,3 @@
1
1
  class PropertybaseId
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -59,7 +59,7 @@ class PropertybaseId
59
59
  end
60
60
 
61
61
  def self.parse(input_id)
62
- raise ArgumentError, "invalid length (#{input_id.size})" if input_id.size != 18
62
+ raise ArgumentError, "invalid length (#{input_id.size})" if input_id.size != max_length
63
63
 
64
64
  _, object_id, host_id, time, process_id, counter = input_id.match(/(\w{3})(\w{2})(\w{6})(\w{2})(\w{5})/).to_a
65
65
 
@@ -74,6 +74,14 @@ class PropertybaseId
74
74
  )
75
75
  end
76
76
 
77
+ def self.max_length
78
+ 18
79
+ end
80
+
81
+ def self.max_value(digits = max_length)
82
+ ("zz" * digits).to_i(36)
83
+ end
84
+
77
85
  private
78
86
 
79
87
  def format_number(integer, length)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propertybase_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leif Gensert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler