char_pool 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -30
- data/char_pool.gemspec +0 -1
- data/lib/char_pool/version.rb +1 -1
- data/lib/char_pool.rb +8 -3
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c34ded892ef60212db978aa48a595a3e04e2e405
|
4
|
+
data.tar.gz: 3f436230efc4806ab276135531c500c48008b176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b928e46d8b89e1e301021c8cd844f5dfad839d729d5ff30ab2573a3fd3ef51903bea151ba107924a708ee8f240b0cf9550c3f2148850749dc65363ace0243c
|
7
|
+
data.tar.gz: 67d5d392c06058911ebc636a02f68396903785fafcb3b01a049b81e91d2a8bc97fba01398d04c0ca890b172ae893ce35cc1d3a602d3d06b4513e50debf90eb5f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CharPool
|
2
2
|
|
3
|
-
This gem will iterate over your chars set, for example if you have chars set ['a', 'b', 'c']
|
3
|
+
This gem will iterate over your chars set, for example if you have chars set `['a', 'b', 'c']`, this gem will produce
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
0 = a
|
@@ -31,29 +31,7 @@ This gem will iterate over your chars set, for example if you have chars set ['a
|
|
31
31
|
19 = acb
|
32
32
|
20 = acc
|
33
33
|
|
34
|
-
|
35
|
-
22 = bab
|
36
|
-
23 = bac
|
37
|
-
|
38
|
-
24 = bba
|
39
|
-
25 = bbb
|
40
|
-
26 = bbc
|
41
|
-
|
42
|
-
27 = bca
|
43
|
-
28 = bcb
|
44
|
-
29 = bcc
|
45
|
-
|
46
|
-
30 = caa
|
47
|
-
31 = cab
|
48
|
-
32 = cac
|
49
|
-
|
50
|
-
33 = cba
|
51
|
-
34 = cbb
|
52
|
-
35 = cbc
|
53
|
-
|
54
|
-
36 = cca
|
55
|
-
37 = ccb
|
56
|
-
38 = ccc
|
34
|
+
...
|
57
35
|
|
58
36
|
39 = aaaa
|
59
37
|
|
@@ -89,15 +67,18 @@ char_pool.next #=> c
|
|
89
67
|
char_pool.next #=> aa
|
90
68
|
char_pool.next #=> ab
|
91
69
|
char_pool.next #=> ac
|
70
|
+
```
|
92
71
|
|
93
|
-
|
94
|
-
|
72
|
+
You can use this as a drop replacement for your URL shortener engine.
|
73
|
+
No need to store your shortened URL as key and value in database, you can just encode database id as the key.
|
95
74
|
|
96
|
-
|
97
|
-
char_pool.
|
98
|
-
```
|
75
|
+
```ruby
|
76
|
+
char_pool = CharPool.new(('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a)
|
99
77
|
|
100
|
-
|
78
|
+
char_pool.index_at(100_000_000_000_000) #=> BxHCH9jC
|
79
|
+
|
80
|
+
char_pool.index('BxHCH9jC') #=> 100_000_000_000_000
|
81
|
+
```
|
101
82
|
|
102
83
|
## Development
|
103
84
|
|
data/char_pool.gemspec
CHANGED
data/lib/char_pool/version.rb
CHANGED
data/lib/char_pool.rb
CHANGED
@@ -2,7 +2,10 @@ require 'char_pool/version'
|
|
2
2
|
|
3
3
|
class CharPool
|
4
4
|
def initialize(char_pool)
|
5
|
-
|
5
|
+
raise(ArgumentError, 'Pool should be array') unless char_pool.is_a?(Array)
|
6
|
+
raise(ArgumentError, 'Pool cannot be empty') if char_pool.empty?
|
7
|
+
|
8
|
+
@char_pool = char_pool.uniq.map &:to_s
|
6
9
|
end
|
7
10
|
|
8
11
|
def start(current = @char_pool.first)
|
@@ -34,8 +37,9 @@ class CharPool
|
|
34
37
|
|
35
38
|
private
|
36
39
|
def decode(string)
|
37
|
-
|
40
|
+
return string.length if @char_pool.length == 1
|
38
41
|
|
42
|
+
array = string.split('').map do |char|
|
39
43
|
@char_pool.index(char)
|
40
44
|
end
|
41
45
|
|
@@ -47,7 +51,8 @@ class CharPool
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def encode(number)
|
50
|
-
return [0]
|
54
|
+
return [0] if number.zero?
|
55
|
+
return [0] * number if @char_pool.length == 1
|
51
56
|
|
52
57
|
seq_index = 0
|
53
58
|
length = @char_pool.length
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: char_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Teja Sophista V.R.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
description:
|
70
56
|
email:
|
71
57
|
- tejanium@yahoo.com
|