micro_token 0.0.1 → 0.0.2

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: 0cf7c23f62271e5acf8354c0ccb9179a91184e65
4
- data.tar.gz: 0930aa0dfcdec54bf852b050dc61f5b11db1f758
3
+ metadata.gz: 344e232941e019cafdbe2fdb47cd6c0a587b64a1
4
+ data.tar.gz: b2bc64c84ecee92c11d48b1f38a896a2992a149a
5
5
  SHA512:
6
- metadata.gz: 0c79c1a4d62a19cb6a5d2188d231b4acfc579b022e76e5c6d5d1311c255ce22f6b020f0c250a28df9e5b6b95ad485807ec2cd50990139fd22ae0a631af9ab4b3
7
- data.tar.gz: d9e7cf0107416672c31e275eb300e44b687377cabde95435f15925c9e2f2ead2583e35985341ee2d31792cd63ba59d5855d66d9683208a9c0861abc42d57f230
6
+ metadata.gz: c296227b6658ed366140097cbf72d766fe293a641cd8f42a4688194223aa8d729fa466e8fbb53602154601aa461ddf3cf7ea5faea18428b29314047cc181e103
7
+ data.tar.gz: 670fd4f827010631d2764509e4dc0645bb60514022375029147216071b6d2778c07938a3d40d5d40335253b0c342d067e329b03bb8d96d4cb29830131dd9cb4e
data/lib/micro_token.rb CHANGED
@@ -2,30 +2,47 @@ require "micro_token/version"
2
2
  require 'securerandom'
3
3
 
4
4
  module MicroToken
5
- ALPHA_CHARS = ('a'..'z').to_a + ('A'..'Z').to_a
5
+ LOWER_ALPHA_CHARS = ('a'..'z').to_a
6
+ UPPER_ALPHA_CHARS = ('A'..'Z').to_a
7
+ NUMERIC_CHARS = (0..9).to_a
8
+ ALPHA_CHARS = LOWER_ALPHA_CHARS + UPPER_ALPHA_CHARS
9
+ ALPHANUMERIC_CHARS = ALPHA_CHARS + NUMERIC_CHARS
6
10
 
7
- def self.generate(length=8,format=:alphanumeric)
8
- (1..length).collect { self.send("_generate_#{format}_char") }.join
9
- end
11
+ class << self
10
12
 
11
- private
13
+ def generate(length=8,format=:alphanumeric)
14
+ (1..length).collect { self.send("_generate_#{format}_char") }.join
15
+ end
12
16
 
13
- def self._generate_alphanumeric_char
14
- (i = rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr
15
- end
17
+ private
16
18
 
17
- def self._generate_numeric_char
18
- rand(9)
19
- end
19
+ def _generate_uppercase_char
20
+ pick_from(UPPER_ALPHA_CHARS)
21
+ end
20
22
 
21
- def self._generate_alpha_char
22
- ALPHA_CHARS[rand(ALPHA_CHARS.size)]
23
- end
23
+ def _generate_lowercase_char
24
+ pick_from(LOWER_ALPHA_CHARS)
25
+ end
26
+
27
+ def _generate_alphanumeric_char
28
+ pick_from(ALPHANUMERIC_CHARS)
29
+ end
24
30
 
25
- private
31
+ def _generate_numeric_char
32
+ pick_from(NUMERIC_CHARS)
33
+ end
34
+
35
+ def _generate_alpha_char
36
+ pick_from(ALPHA_CHARS)
37
+ end
38
+
39
+ def rand(n)
40
+ SecureRandom.random_number(n)
41
+ end
42
+
43
+ def pick_from(ary)
44
+ ary[rand(ary.size)]
45
+ end
26
46
 
27
- def rand(n)
28
- SecureRandom.random_number(n)
29
47
  end
30
48
  end
31
-
@@ -1,3 +1,3 @@
1
1
  module MicroToken
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -53,6 +53,26 @@ describe MicroToken do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ context 'set to uppercase' do
58
+ let(:format) { :uppercase }
59
+
60
+ 23.times do
61
+ it 'contains only uppercase letters' do
62
+ expect(subject.split.all? { |c| c =~ /[A-Z]/ }).to be_true
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'set to lowercase' do
68
+ let(:format) { :lowercase }
69
+
70
+ 23.times do
71
+ it 'contains only lowercase letters' do
72
+ expect(subject.split.all? { |c| c =~ /[a-z]/ }).to be_true
73
+ end
74
+ end
75
+ end
56
76
  end
57
77
 
58
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_token
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
  - James Harton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.0.3
93
+ rubygems_version: 2.0.0
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: A tiny random token generator