short_id 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/short_id.rb +12 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bafe408c160600ab91dd786b334df6d47e92d5e
4
- data.tar.gz: 37b0cf2e2b43bf63882000fbe95dbedd39c29b3e
3
+ metadata.gz: 446d6270267405153659e8d5fa3227d78243d258
4
+ data.tar.gz: a967dd6ec895cde28380d8f2243b94da02bf6a6f
5
5
  SHA512:
6
- metadata.gz: dc9d2f10e233ca1bf2df12fa452adfa56e5da210912e743a8c344be67befc1919ec3d7f4ff320214393acd4c338910c6b8ff2587804fe53fe1fae9a6a3379166
7
- data.tar.gz: a93b044167f2516e8b6435afeaa14ca10fc8a6c82ab10fdd84737879cc8cb9d7975381dbae864cb48baee20b5db0a51a92a28f11c0ed35dd45e63c7735b4e355
6
+ metadata.gz: 6b30de6dca9f3045def645a84c0cd36384289b183955788bda7163a0cf5bcb5d866d1edf1e87d26a7bc93b8922b244e394c1fb21730ddcdbae88326e4d85fd63
7
+ data.tar.gz: a6578f163d923f52178162107331e9dabe87f5ca98ef511b21371bba99c7723be8fcb352d659e7861a534cd5b238bec58ce3363f73add5fcc73efc1d7d0cc0a8
@@ -2,17 +2,19 @@ require_relative 'id_chars.rb'
2
2
 
3
3
  ID_CHARS_LENGTH = ID_CHARS.length
4
4
 
5
- def int_to_short_id(n)
6
- raise "N must be greater than 0" unless n > 0
7
- id = ''
5
+ class ShortId
6
+ def self.int_to_short_id(n)
7
+ raise "N must be greater than 0" unless n > 0
8
+ id = ''
8
9
 
9
- places = Math.log(n, ID_CHARS_LENGTH).floor
10
+ places = Math.log(n, ID_CHARS_LENGTH).floor
10
11
 
11
- places.downto(0).each do |place|
12
- div, remainder = n.divmod(ID_CHARS_LENGTH ** place)
13
- id += ID_CHARS[div - 1]
14
- n = remainder
15
- end
12
+ places.downto(0).each do |place|
13
+ div, remainder = n.divmod(ID_CHARS_LENGTH ** place)
14
+ id += ID_CHARS[div - 1]
15
+ n = remainder
16
+ end
16
17
 
17
- return id
18
+ return id
19
+ end
18
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: short_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Bunday