obfuscated_identifier 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3fe76e8c21cff5d81384599c49de05b53dd6f26
4
- data.tar.gz: d15816d65ee76a1226a826853c98441b41d0d553
3
+ metadata.gz: 5f05e9a15ddbdc7de72525602c9c3e9713af8907
4
+ data.tar.gz: 4b4eb21cb3a9e5493e190ce081d5e4404fba7651
5
5
  SHA512:
6
- metadata.gz: 6f2d887a344032f28fe86aacd2c947771d0be33daeadbd27209235527500ffef86350261c1aaeb3f80f21ed0fe71703c93ce87c36509dedc20b8ab2e712303f7
7
- data.tar.gz: 36633ab880ea8269782db357193943c65005c3840ab0100fc57b419d312f90a2d62f1ff05eab7b1b669e53c7002d4b4797f7d75d6a0fb51830eda80ca0919dca
6
+ metadata.gz: 407aabe099a93f6f8cd4765dc98b5b1cb7bb1e5cead3a956e1d636a44034cf6a29400507294de0680e680460de91d94bcd86334114f11bd79ffc7e53574553d7
7
+ data.tar.gz: 6bce6c15a8298251bd46dcea0d8b91a04e9447c51b07faf4b4b46b2da2ca4f444ea2a93b9967c950bb134569f2f312b3775d189c3a2d67e072e48e1cb040123d
@@ -1,3 +1,3 @@
1
1
  module ObfuscatedIdentifier
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
- it 'returns a number' do
68
- expect(klass.from_identifier(example_identifier)).to be_instance_of(Fixnum)
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
- it 'returns the expected integer' do
72
- expect(klass.from_identifier(example_identifier)).to eq(example_number)
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.2
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-04 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport