token_phrase 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/README.md +32 -32
- data/Rakefile +9 -0
- data/lib/token_phrase.rb +8 -43
- data/lib/token_phrase/dictionary.rb +32 -0
- data/lib/token_phrase/generator.rb +34 -0
- data/lib/token_phrase/version.rb +1 -1
- data/test/generator_test.rb +57 -0
- data/test/test_helper.rb +1 -0
- data/token_phrase.gemspec +3 -0
- metadata +44 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80a20c320997d8d943ec26d8544e7f7c89fb83e5
|
4
|
+
data.tar.gz: 047ae5ab470309acf7acdddb24ca565933a892b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb8ce0a04edcc6a41b66feba1d1e174450496cf1c5d13e0d96d0e8ac684828c0de6815659f733981099f6fb46956b53b31ea8a58c9f1c4f73b06db132d25cd2a
|
7
|
+
data.tar.gz: 31ca6d9702ac40a648b0a7130434a4f5a58f4f426669a6a0f702c9f464b32bc3433ed519e902ba4e5fc399092f42777ff375ee9fb77f38db23d90ef28c3eb4ad
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# TokenPhrase
|
1
|
+
# TokenPhrase (v1.0.4)
|
2
|
+
[![Build Status](https://travis-ci.org/genericsteele/token_phrase.png?branch=master)](https://travis-ci.org/genericsteele/token_phrase)
|
2
3
|
|
3
4
|
TokenPhrase is a simple gem that generates unique phrases for you to use in your app as tokens.
|
4
5
|
|
5
6
|
"Why?" you may be asking. Why not? Token phrases give your app a little personality and make support a lot easier.
|
6
7
|
|
7
|
-
TokenPhrase was built for [Sellmer](http://justsellstuff.com), a simple yet powerful way to sell your digital goods.
|
8
|
-
|
9
8
|
## Installation
|
10
9
|
|
11
10
|
Add this line to your application's Gemfile:
|
@@ -27,14 +26,14 @@ By default, TokenPhrase uses the included dictionaries, separates everything wit
|
|
27
26
|
|
28
27
|
```ruby
|
29
28
|
TokenPhrase.generate
|
30
|
-
=> "
|
29
|
+
=> "groovy-red-fractal-fork-101589"
|
31
30
|
|
32
31
|
5.times { p TokenPhrase.generate }
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"sweet-
|
32
|
+
"bodacious-blue-spotted-envelope-428491"
|
33
|
+
"magnetic-burnt-orange-polka-dotted-spider-wolf-268974"
|
34
|
+
"conservative-plum-paisley-banana-slug-771632"
|
35
|
+
"bluetooth-chiffon-houndstooth-wolf-spider-700306"
|
36
|
+
"sweet-violet-tartan-coyote-16101"
|
38
37
|
```
|
39
38
|
|
40
39
|
With the current dictionaries and numbers, there are 4,199,040,000,000 (four trillion!) unique possibilites.
|
@@ -44,10 +43,10 @@ If you would like a different separator, just pass a string as an argument:
|
|
44
43
|
|
45
44
|
```ruby
|
46
45
|
TokenPhrase.generate('$')
|
47
|
-
=> "
|
46
|
+
=> "groovy$salmon$paisley$cape$848536"
|
48
47
|
|
49
48
|
TokenPhrase.generate('MARSIPAN')
|
50
|
-
=> "
|
49
|
+
=> "sugarfilledMARSIPANcrimsonMARSIPANstripedMARSIPANfrogMARSIPAN860203"
|
51
50
|
```
|
52
51
|
|
53
52
|
### Dictionaries
|
@@ -62,35 +61,35 @@ If you want to replace the dictionary, just pass a hash with an array as an argu
|
|
62
61
|
|
63
62
|
```ruby
|
64
63
|
TokenPhrase.generate :adjectives => %w(glowing)
|
65
|
-
=> "glowing-
|
64
|
+
=> "glowing-peach-glossy-barracuda-743220"
|
66
65
|
|
67
66
|
5.times { p TokenPhrase.generate :nouns => %w(Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto) }
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"
|
72
|
-
"
|
67
|
+
"stupendous-crimson-tartan-Uranus-431203"
|
68
|
+
"tailored-khaki-fractal-Neptune-957683"
|
69
|
+
"better-almond-striped-Pluto-299491"
|
70
|
+
"soft-chiffon-tartan-Saturn-29752"
|
71
|
+
"tailored-azure-honeycomb-Saturn-668823"
|
73
72
|
```
|
74
73
|
You can pass multiple dictionaries:
|
75
74
|
|
76
75
|
```ruby
|
77
76
|
5.times { p TokenPhrase.generate :colors => %w(black white), :nouns => %w(cat dog) }
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
77
|
+
"windy-white-satin-dog-663888"
|
78
|
+
"exciting-black-spotted-cat-502218"
|
79
|
+
"sour-white-houndstooth-cat-591001"
|
80
|
+
"thunderous-white-pinstriped-cat-375006"
|
81
|
+
"grandpas-white-honeycomb-cat-23992"
|
83
82
|
```
|
84
83
|
|
85
84
|
And you can, of course pass a separator before the dictionaries:
|
86
85
|
|
87
86
|
```ruby
|
88
87
|
5.times { p TokenPhrase.generate '^^^', :patterns => %w(striped), :adjectives =>%w(great awesome) }
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"
|
92
|
-
"awesome^^^
|
93
|
-
"awesome^^^
|
88
|
+
"awesome^^^aquamarine^^^striped^^^pen^^^345915"
|
89
|
+
"great^^^salmon^^^striped^^^pants^^^852927"
|
90
|
+
"great^^^white^^^striped^^^spider^^^wolf^^^646401"
|
91
|
+
"awesome^^^blue^^^striped^^^people^^^314195"
|
92
|
+
"awesome^^^aqua^^^striped^^^wolverine^^^113478"
|
94
93
|
```
|
95
94
|
|
96
95
|
### Numbers
|
@@ -99,7 +98,7 @@ To help with uniqueness, a random number is added to the token by default. This
|
|
99
98
|
|
100
99
|
```ruby
|
101
100
|
TokenPhrase.generate(:numbers => false)
|
102
|
-
=> "
|
101
|
+
=> "energetic-yellow-pinstriped-skunk"
|
103
102
|
```
|
104
103
|
|
105
104
|
## Dictionary Methods
|
@@ -115,8 +114,9 @@ Each of these dictionary methods accept an array as an argument that will merge
|
|
115
114
|
|
116
115
|
```ruby
|
117
116
|
your_patterns = TokenPhrase.patterns %w(magic-eye)
|
118
|
-
TokenPhrase.generate :patterns => your_patterns
|
119
|
-
|
117
|
+
2.times { p TokenPhrase.generate :patterns => your_patterns }
|
118
|
+
"prickly-magenta-matte-space-heater-687093"
|
119
|
+
"stupendous-aquamarine-magic-eye-skunk-690072"
|
120
120
|
```
|
121
121
|
|
122
122
|
## TokenPhrase.permutations(dictionaries = {})
|
@@ -160,6 +160,6 @@ end
|
|
160
160
|
4. Push to the branch (`git push origin my-new-feature`)
|
161
161
|
5. Create new Pull Request
|
162
162
|
|
163
|
-
##
|
163
|
+
## Thanks
|
164
164
|
|
165
|
-
|
165
|
+
Thanks to [benolee](https://github.com/benolee) for [refactoring the generator model](https://github.com/genericsteele/token_phrase/commit/7e5a0877882ba7d08f0c5a40d7873ebb0d205a45)!
|
data/Rakefile
CHANGED
data/lib/token_phrase.rb
CHANGED
@@ -1,49 +1,14 @@
|
|
1
|
+
require "token_phrase/dictionary"
|
2
|
+
require "token_phrase/generator"
|
1
3
|
require "token_phrase/version"
|
2
4
|
|
3
5
|
module TokenPhrase
|
4
|
-
|
5
|
-
|
6
|
-
Patterns = %w(striped checked spotted polka-dotted plaid wavy houndstooth argyle glossy matte pinstriped tartan paisley satin honeycomb fractal waved cracked )
|
7
|
-
Nouns = %w(floutist carpenter jacket president address machine computer mug lamp phone wall bicycle river lake fountain building book hat pants shirt cape soup gloves pen suit photograph sand profit energy fork compact-disk floppy-disk chandelier door window laboratory people tapir wolverine wolf spider wolf-spider spider-wolf banana-slug giraffe deer-mouse capybara dingo dragon cardinal owl octopus elk moose weasel elephant rhino iguana bullfrog greyhound stickbug ladybug ant rat coyote chimpanzee housecat barracuda raven crane fox panda racoon nessie whale dolphin shark viper frog toad flounder skunk wookie dishwasher bat space-heater bobble-head lego-set pinboard flag tv video-game envelope headphones mousepad jukebox)
|
8
|
-
Numbers = [*1..100]
|
9
|
-
|
10
|
-
def self.adjectives(more_adjectives = nil)
|
11
|
-
more_adjectives.nil? ? TokenPhrase::Adjectives : TokenPhrase::Adjectives | more_adjectives
|
6
|
+
def self.generate *args
|
7
|
+
Generator.new(*args).generate
|
12
8
|
end
|
13
|
-
|
14
|
-
def self.
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.patterns(more_patterns = nil)
|
19
|
-
more_patterns.nil? ? TokenPhrase::Patterns : TokenPhrase::Patterns | more_patterns
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.nouns(more_nouns = nil)
|
23
|
-
more_nouns.nil? ? TokenPhrase::Nouns : TokenPhrase::Nouns | more_nouns
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.generate(separator = nil, dictionaries = {})
|
27
|
-
if separator.is_a?(Hash)
|
28
|
-
dictionaries = separator
|
29
|
-
separator = nil
|
30
|
-
end
|
31
|
-
dictionaries[:adjectives] ||= TokenPhrase::Adjectives
|
32
|
-
dictionaries[:colors] ||= TokenPhrase::Colors
|
33
|
-
dictionaries[:patterns] ||= TokenPhrase::Patterns
|
34
|
-
dictionaries[:nouns] ||= TokenPhrase::Nouns
|
35
|
-
phrase = [dictionaries[:adjectives].sample, dictionaries[:colors].sample, dictionaries[:patterns].sample, dictionaries[:nouns].sample].join('-')
|
36
|
-
phrase << Random.new.rand(1..1000000).to_s unless dictionaries[:numbers] == false
|
37
|
-
phrase.gsub!(/-/, separator) unless separator.nil?
|
38
|
-
return phrase
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.permutations(dictionaries = {})
|
42
|
-
dictionaries[:adjectives] ||= TokenPhrase::Adjectives
|
43
|
-
dictionaries[:colors] ||= TokenPhrase::Colors
|
44
|
-
dictionaries[:patterns] ||= TokenPhrase::Patterns
|
45
|
-
dictionaries[:nouns] ||= TokenPhrase::Nouns
|
46
|
-
permutations = [:adjectives, :colors, :patterns, :nouns].map{ |key| dictionaries[key].uniq.count }.inject{ |product, total| product * total }
|
47
|
-
dictionaries[:numbers] == false ? permutations : permutations * 1000000
|
9
|
+
|
10
|
+
def self.permutations *args
|
11
|
+
Generator.new(*args).permutations
|
48
12
|
end
|
49
13
|
end
|
14
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module TokenPhrase
|
2
|
+
def self.dictionary
|
3
|
+
{
|
4
|
+
:adjectives => %w(wireless furry fuzzy sleek messy incredible generous splendid superior spectacular amazing ultimate ferocious exciting lovely old-fashioned home-made grass-fed free-range grandmas grandpas governing prickly strong stellar awesome wonderful bodacious excellent stupendous groovy dancing energetic sweet sour sugarfilled glazed vegan letterman thunderous established magnetic better windy wind-up american soft genetically-modified tailored liberal conservative bluetooth),
|
5
|
+
:colors => %w(red yellow blue green violet taupe mauve lime golden silver grey black white tangello sunshine brown tan infrared ultraviolet pink beige almond aquamarine burnt-orange cerulean cornflower-blue denim forest-green midnight-blue peach plum sea-green ruby emerald jade rose topaz onyx pearl coral crimson cyan chocolate aqua azure lavendar chiffon khaki ivory magenta navy-blue olive salmon turquoise),
|
6
|
+
:patterns => %w(striped checked spotted polka-dotted plaid wavy houndstooth argyle glossy matte pinstriped tartan paisley satin honeycomb fractal waved cracked ),
|
7
|
+
:nouns => %w(floutist carpenter jacket president address machine computer mug lamp phone wall bicycle river lake fountain building book hat pants shirt cape soup gloves pen suit photograph sand profit energy fork compact-disk floppy-disk chandelier door window laboratory people tapir wolverine wolf spider wolf-spider spider-wolf banana-slug giraffe deer-mouse capybara dingo dragon cardinal owl octopus elk moose weasel elephant rhino iguana bullfrog greyhound stickbug ladybug ant rat coyote chimpanzee housecat barracuda raven crane fox panda racoon nessie whale dolphin shark viper frog toad flounder skunk wookie dishwasher bat space-heater bobble-head lego-set pinboard flag tv video-game envelope headphones mousepad jukebox bacon eggs cereal milk sausage ham turkey nerf-gun bowl plate lazy-susan safe fireworks table chair muscles trek journey quest mission laser-gun gladiator pumpkin),
|
8
|
+
:numbers => (1..1000000).to_a
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.adjectives more = []
|
13
|
+
dictionary[:adjectives] | more
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.colors more = []
|
17
|
+
dictionary[:colors] | more
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.patterns more = []
|
21
|
+
dictionary[:patterns] | more
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.nouns more = []
|
25
|
+
dictionary[:nouns] | more
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.numbers more = []
|
29
|
+
dictionary[:numbers] | more
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'backports/1.9.1/array/sample'
|
2
|
+
module TokenPhrase
|
3
|
+
class Generator
|
4
|
+
attr_accessor :separator, :dictionary, :order
|
5
|
+
|
6
|
+
def initialize separator = "-", options = {}
|
7
|
+
separator, options = "-", separator if separator.is_a? Hash
|
8
|
+
options[:numbers] = [] if options[:numbers] == false
|
9
|
+
|
10
|
+
@separator = separator
|
11
|
+
@dictionary = TokenPhrase.dictionary.merge options
|
12
|
+
@order = dictionary.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate
|
16
|
+
lists.map(&:sample).join(separator).chomp(separator).gsub(/-/, separator)
|
17
|
+
end
|
18
|
+
|
19
|
+
def permutations
|
20
|
+
lists.inject 1 do |p, list|
|
21
|
+
if list.empty?
|
22
|
+
p
|
23
|
+
else
|
24
|
+
p * list.uniq.count
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def lists
|
30
|
+
dictionary.values_at(*order).compact
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/lib/token_phrase/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'token_phrase'
|
3
|
+
|
4
|
+
class GeneratorTest < MiniTest::Unit::TestCase
|
5
|
+
def test_that_numbers_can_be_excluded
|
6
|
+
phrase = TokenPhrase.generate :numbers => false
|
7
|
+
refute_match /\d+$/, phrase
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_that_permutations_calculate_all_combinations
|
11
|
+
permutations = TokenPhrase.permutations(
|
12
|
+
:adjectives => %w(test),
|
13
|
+
:colors => %w(test),
|
14
|
+
:patterns => %w(test),
|
15
|
+
:nouns => %w(test),
|
16
|
+
:numbers => false
|
17
|
+
)
|
18
|
+
assert_equal 1, permutations
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_that_separator_can_be_overridden
|
22
|
+
phrase = TokenPhrase.generate "+"
|
23
|
+
assert_match /\+/, phrase
|
24
|
+
refute_match /-/, phrase
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_adjectives_can_be_overridden
|
28
|
+
phrase = TokenPhrase.generate :adjectives => %w(test)
|
29
|
+
assert_match /test/, phrase
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_that_colors_can_be_overridden
|
33
|
+
phrase = TokenPhrase.generate :colors => %w(test)
|
34
|
+
assert_match /test/, phrase
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_that_patterns_can_be_overridden
|
38
|
+
phrase = TokenPhrase.generate :patterns => %w(test)
|
39
|
+
assert_match /test/, phrase
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_that_nouns_can_be_overridden
|
43
|
+
phrase = TokenPhrase.generate :nouns => %w(test)
|
44
|
+
assert_match /test/, phrase
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_that_dictionaries_can_be_added_to
|
48
|
+
adjectives = TokenPhrase.adjectives %w(test)
|
49
|
+
colors = TokenPhrase.colors %w(test)
|
50
|
+
patterns = TokenPhrase.patterns %w(test)
|
51
|
+
nouns = TokenPhrase.nouns %w(test)
|
52
|
+
assert_equal (TokenPhrase.adjectives.count + 1), adjectives.count
|
53
|
+
assert_equal (TokenPhrase.colors.count + 1), colors.count
|
54
|
+
assert_equal (TokenPhrase.patterns.count + 1), patterns.count
|
55
|
+
assert_equal (TokenPhrase.nouns.count + 1), nouns.count
|
56
|
+
end
|
57
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/autorun'
|
data/token_phrase.gemspec
CHANGED
@@ -4,6 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'token_phrase/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
+
gem.add_dependency 'backports'
|
8
|
+
gem.add_development_dependency 'minitest'
|
9
|
+
|
7
10
|
gem.name = "token_phrase"
|
8
11
|
gem.version = TokenPhrase::VERSION
|
9
12
|
gem.authors = ["Eric Steele"]
|
metadata
CHANGED
@@ -1,16 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: token_phrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Eric Steele
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
11
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: backports
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
14
41
|
description: A token-phrase generator
|
15
42
|
email:
|
16
43
|
- eric@notvelcro.com
|
@@ -19,36 +46,42 @@ extensions: []
|
|
19
46
|
extra_rdoc_files: []
|
20
47
|
files:
|
21
48
|
- .gitignore
|
49
|
+
- .travis.yml
|
22
50
|
- Gemfile
|
23
51
|
- LICENSE.txt
|
24
52
|
- README.md
|
25
53
|
- Rakefile
|
26
54
|
- lib/token_phrase.rb
|
55
|
+
- lib/token_phrase/dictionary.rb
|
56
|
+
- lib/token_phrase/generator.rb
|
27
57
|
- lib/token_phrase/version.rb
|
58
|
+
- test/generator_test.rb
|
59
|
+
- test/test_helper.rb
|
28
60
|
- token_phrase.gemspec
|
29
61
|
homepage: https://github.com/genericsteele/token_phrase
|
30
62
|
licenses: []
|
63
|
+
metadata: {}
|
31
64
|
post_install_message:
|
32
65
|
rdoc_options: []
|
33
66
|
require_paths:
|
34
67
|
- lib
|
35
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
69
|
requirements:
|
38
|
-
- -
|
70
|
+
- - '>='
|
39
71
|
- !ruby/object:Gem::Version
|
40
72
|
version: '0'
|
41
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
74
|
requirements:
|
44
|
-
- -
|
75
|
+
- - '>='
|
45
76
|
- !ruby/object:Gem::Version
|
46
77
|
version: '0'
|
47
78
|
requirements: []
|
48
79
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
80
|
+
rubygems_version: 2.0.3
|
50
81
|
signing_key:
|
51
|
-
specification_version:
|
82
|
+
specification_version: 4
|
52
83
|
summary: Token Phrase is a simple generator that creates friendlier unique tokens
|
53
84
|
as phrases
|
54
|
-
test_files:
|
85
|
+
test_files:
|
86
|
+
- test/generator_test.rb
|
87
|
+
- test/test_helper.rb
|