readable-token 0.1.0a → 0.1.0

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: bc23a3a8458248c0942242a0533b312da56af97d
4
- data.tar.gz: 53f48a46cc46d711464e31342b903fcb684659c6
3
+ metadata.gz: 61f4a07f28254f0700997c34242a384860624614
4
+ data.tar.gz: a7d272ac34c7db671bdfb6df2cca39fbc528aa94
5
5
  SHA512:
6
- metadata.gz: 7ced1ed8683e1d289e05d94eb630de2c12fed73db4be739893f1d278fa70d89d4e68327a3953e99662f202c24307f2d79e5f1da3f5cc4f9d5d132f1662181caa
7
- data.tar.gz: 15b1988ac12655c9a4a46a389971d10e687affd3bfba4c53185dad5243a8f6ecd6ec1ccb5070c2f78e6d243f3a5d90c02e1b821c60e3cbf45c5a4271bbec57f3
6
+ metadata.gz: a665f67d6e2bd5f6d6504c87fd27ab36dcbf0751c16be6afef992fb0ddbf29eeca59f8c2dfc72b52aa620a1b65950f0a2f2a2c4e16a3693acb6850b12fd4d427
7
+ data.tar.gz: 7965e8bb82bbcc51776f29009f975c91563af5273f8723a1bbbbf72d8adc6b3a3f9228b8adaf04ea63ab8720abc59dd91930790b397d31534f44d5ba55700c03
data/HISTORY.md CHANGED
@@ -1,3 +1,3 @@
1
- ## HEAD
1
+ ## 0.1.0 (2014-12-01)
2
2
 
3
- * Initial development/hacking initiated.
3
+ * Initial version.
data/README.md CHANGED
@@ -24,14 +24,14 @@ Require the gem in your code:
24
24
 
25
25
  ### Generate a token
26
26
 
27
- ReadableToken.generate
28
- ReadableToken.generate(min: 6)
29
- ReadableToken.generate(max: 8)
30
- ReadableToken.generate(separator: '|')
27
+ ReadableToken.generate # => "barista-spoon-1"
28
+ ReadableToken.generate(min: 20) # => "doughnut-fork-aroma-7"
29
+ ReadableToken.generate(max: 10) # => "penguin-2"
31
30
 
32
31
  ### Loading your own word list
33
32
 
34
- generator = ReadableToken.new(%w(cat penguin password))
33
+ ReadableToken.words = %w(cat penguin password)
34
+ ReadableToken.generate
35
35
 
36
36
  # Development
37
37
 
@@ -42,5 +42,3 @@ Require the gem in your code:
42
42
 
43
43
  # hints where to improve docs
44
44
  bundle exec inch
45
-
46
- # TODO
@@ -1,32 +1,41 @@
1
1
  require 'readable-token/version'
2
2
 
3
- class ReadableToken
3
+ # A tiny Ruby library for generating human readable "tokens".
4
+ module ReadableToken
4
5
 
5
- def initialize
6
- @records = []
6
+ # Access to current list of words
7
+ def self.words
8
+ @@words ||= %w{dream season applause music venue talk top spoon fork tea coffee soup eat drink chat social happy doughnut beans bistro cafe lunch java ruby penguin lion leopard cake tiger crab fish moo milk owl roast aroma balance barista blend body decaf espresso flavor mocha latte organic friend}
7
9
  end
8
10
 
11
+ # Set list of words to the given array
12
+ def self.words=(vals)
13
+ @@words = vals
14
+ end
15
+
16
+ # Generate a new token.
9
17
  def self.generate(opts = {})
18
+ # set default options and merge with user provided
10
19
  options = {
11
20
  min: 8,
12
21
  max: nil
13
22
  }.merge(opts)
14
23
 
15
- words = %w{music venue talk top spoon fork tea coffee soup eat drink chat social happy doughnut beans bistro cafe lunch java ruby penguin lion leopard cake tiger crab fish moo milk owl roast aroma balance barista blend body decaf espresso flavor mocha latte organic friend}
16
-
17
24
  segments = []
18
25
 
19
26
  # add number
20
27
  segments << rand(1..9).to_s
21
28
 
29
+ # count number of loops so were not spinning our wheels if we can't meet
30
+ # the criteria requested by the user.
22
31
  looped = 0
23
32
  while current_length_of(segments) < options[:min]
24
- segments.delete_if(&:nil?).delete_if(&:empty?)
33
+ new_word = ''
34
+ remove_blanks!(segments)
35
+
25
36
  looped += 1
26
37
  break if looped > 20
27
38
 
28
- new_word = ''
29
-
30
39
  current_length = current_length_of(segments)
31
40
  if options[:max] && options[:max] > 0
32
41
  remaining = options[:max] - current_length
@@ -40,7 +49,7 @@ class ReadableToken
40
49
 
41
50
  segments << new_word
42
51
  end
43
- segments.delete_if(&:nil?).delete_if(&:empty?)
52
+ remove_blanks!(segments)
44
53
 
45
54
  # join it all together to give us a token
46
55
  segments.reverse.join('-')
@@ -48,13 +57,19 @@ class ReadableToken
48
57
 
49
58
  private
50
59
 
60
+ # Remove blank, empty, nil array elements
61
+ def self.remove_blanks!(segments)
62
+ segments.delete_if(&:nil?).delete_if(&:empty?)
63
+ end
64
+
65
+ # Calculate the current length
51
66
  def self.current_length_of(segments)
52
67
  segments.join('-').length
53
68
  end
54
69
 
70
+ # Filter array of words by their maximum length
55
71
  def self.filter_by_length(words, max)
56
- filtered = words.select { |w| w.length <= max }
57
- filtered
72
+ words.select { |w| w.length <= max }
58
73
  end
59
74
 
60
75
  end
@@ -1,3 +1,3 @@
1
- class ReadableToken
2
- Version = '0.1.0a'
1
+ module ReadableToken
2
+ Version = '0.1.0'
3
3
  end
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
18
18
 
19
19
  # development dependencies
20
20
  s.add_development_dependency('bundler', '~> 1.0')
21
- s.add_development_dependency('rake', '>= 9.0')
21
+ s.add_development_dependency('rake', '~> 9.0')
22
22
  s.add_development_dependency('minitest', '~> 5.0')
23
23
  s.add_development_dependency('simplecov', '~> 0.7.1')
24
24
  s.add_development_dependency('yard', '~> 0.8')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readable-token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0a
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Antins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '9.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '9.0'
41
41
  - !ruby/object:Gem::Dependency
@@ -128,9 +128,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">"
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.3.1
133
+ version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 2.4.2