obfuscated_identifier 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 +4 -4
- data/lib/obfuscated_identifier/version.rb +1 -1
- data/lib/obfuscated_identifier.rb +10 -0
- data/spec/obfuscated_identifier_spec.rb +38 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f05e9a15ddbdc7de72525602c9c3e9713af8907
|
4
|
+
data.tar.gz: 4b4eb21cb3a9e5493e190ce081d5e4404fba7651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407aabe099a93f6f8cd4765dc98b5b1cb7bb1e5cead3a956e1d636a44034cf6a29400507294de0680e680460de91d94bcd86334114f11bd79ffc7e53574553d7
|
7
|
+
data.tar.gz: 6bce6c15a8298251bd46dcea0d8b91a04e9447c51b07faf4b4b46b2da2ca4f444ea2a93b9967c950bb134569f2f312b3775d189c3a2d67e072e48e1cb040123d
|
@@ -31,6 +31,8 @@ module ObfuscatedIdentifier
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def from_identifier(value)
|
34
|
+
return nil unless valid_identifier_pattern?(value)
|
35
|
+
|
34
36
|
counts = value.each_char.map { |c| @identifier_pattern.index(c.to_s) }.reverse
|
35
37
|
|
36
38
|
numbers = counts[0..-2].each_with_index.map do |count, index|
|
@@ -40,6 +42,14 @@ module ObfuscatedIdentifier
|
|
40
42
|
numbers.join('').to_i
|
41
43
|
end
|
42
44
|
|
45
|
+
def valid_identifier_pattern?(value)
|
46
|
+
return false if value.nil? || value == ''
|
47
|
+
return false if value.length != @identifier_length
|
48
|
+
return false if value.match(/[^a-f 0-9]/)
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
43
53
|
def to_identifier(value)
|
44
54
|
padded_string = pad_number(value)
|
45
55
|
|
@@ -64,12 +64,46 @@ describe ObfuscatedIdentifier do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
describe '.from_identifier' do
|
67
|
-
|
68
|
-
|
67
|
+
context 'when the identifier is valid' do
|
68
|
+
it 'returns a number' do
|
69
|
+
expect(klass.from_identifier(example_identifier)).to be_instance_of(Fixnum)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the expected integer' do
|
73
|
+
expect(klass.from_identifier(example_identifier)).to eq(example_number)
|
74
|
+
end
|
69
75
|
end
|
70
76
|
|
71
|
-
|
72
|
-
|
77
|
+
context 'when the identifier is nil' do
|
78
|
+
let(:example_identifier) { 'nil' }
|
79
|
+
|
80
|
+
it 'returns nil' do
|
81
|
+
expect(klass.from_identifier(example_identifier)).to be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when the identifier is blank' do
|
86
|
+
let(:example_identifier) { '' }
|
87
|
+
|
88
|
+
it 'returns nil' do
|
89
|
+
expect(klass.from_identifier(example_identifier)).to be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when the identifier is an invalid length' do
|
94
|
+
let(:example_identifier) { 'foo' }
|
95
|
+
|
96
|
+
it 'returns nil' do
|
97
|
+
expect(klass.from_identifier(example_identifier)).to be_nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when the identifier contains invalid characters' do
|
102
|
+
let(:example_identifier) { 'b2801d946ae53cz*' }
|
103
|
+
|
104
|
+
it 'returns nil' do
|
105
|
+
expect(klass.from_identifier(example_identifier)).to be_nil
|
106
|
+
end
|
73
107
|
end
|
74
108
|
end
|
75
109
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obfuscated_identifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|