token_phrase 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # TokenPhrase
2
2
 
3
- TODO: Write a gem description
3
+ TokenPhrase is a simple gem that generates unique phrases for you to use in your app as tokens.
4
+
5
+ "Why?" you may be asking. Why not? Token phrases give your app a little personality and make support a lot easier.
6
+
7
+ TokenPhrase was built for [Sellmer](http://justsellstuff.com), a simple yet powerful way to sell your digital goods.
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,9 +20,94 @@ Or install it yourself as:
16
20
 
17
21
  $ gem install token_phrase
18
22
 
19
- ## Usage
23
+ ## TokenPhrase.generate(separator = nil, dictionaries = {})
24
+
25
+ ### Defaults
26
+ By default, TokenPhrase uses the included dictionaries and separates everything with a hyphen (-):
27
+
28
+ ```ruby
29
+ TokenPhrase.generate
30
+ => "ultimate-blue-glossy-lamp"
31
+
32
+ 5.times { p TokenPhrase.generate }
33
+ "energetic-white-checked-book"
34
+ "genetically-modified-red-argyle-lego-set"
35
+ "strong-yellow-wavy-machine"
36
+ "sugarfilled-blue-glossy-jacket"
37
+ "sour-ultraviolet-plaid-sand"
38
+ ```
39
+
40
+ ### Separators
41
+ If you would like a different separator, just pass a string as an argument:
42
+
43
+ ```ruby
44
+ TokenPhrase.generate('$')
45
+ => "exciting$taupe$glossy$lake"
46
+
47
+ TokenPhrase.generate('!!!eric!!!')
48
+ => "splendid!!!eric!!!golden!!!eric!!!glossy!!!eric!!!flounder"
49
+ ```
50
+
51
+ ### Dictionaries
52
+ TokenPhrase combines words from four different dictionaries:
53
+
54
+ * :adjectives
55
+ * :colors
56
+ * :patterns
57
+ * :nouns
58
+
59
+ If you want to replace the dictionary, just pass a hash with an array as an argument:
60
+
61
+ ```ruby
62
+ TokenPhrase.generate :adjectives => %w(glowing)
63
+ => "glowing-tan-striped-sand"
64
+
65
+ 5.times { p TokenPhrase.generate :nouns => %w(Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto) }
66
+ "home-made-lime-plaid-Pluto"
67
+ "bluetooth-lime-wavy-Jupiter"
68
+ "sugarfilled-tan-pinstriped-Mars"
69
+ "magnetic-pink-polka-dotted-Saturn"
70
+ "grandmas-white-plaid-Pluto"
71
+ ```
72
+ You can pass multiple dictionaries:
73
+
74
+ ```ruby
75
+ 5.times { p TokenPhrase.generate :colors => %w(black white), :nouns => %w(cat dog) }
76
+ "spectacular-white-argyle-dog"
77
+ "wind-up-white-plaid-cat"
78
+ "glazed-white-polka-dotted-cat"
79
+ "bodacious-white-checked-cat"
80
+ "genetically-modified-white-pinstriped-dog"
81
+ ```
82
+
83
+ And you can, of course pass a separator before the dictionaries:
84
+
85
+ ```ruby
86
+ 5.times { p TokenPhrase.generate '^^^', :patterns => %w(striped), :adjectives =>%w(great awesome) }
87
+ "great^^^brown^^^striped^^^door"
88
+ "great^^^silver^^^striped^^^carpenter"
89
+ "great^^^lime^^^striped^^^crane"
90
+ "great^^^taupe^^^striped^^^envelope"
91
+ "great^^^pink^^^striped^^^sand"
92
+ ```
93
+
94
+ ## Dictionary Methods
95
+
96
+ If you like the existing dictionaries, but want to add your own words, you can use get an array of each dictionary:
97
+
98
+ * TokenPhrase.adjectives(more_adjectives = nil)
99
+ * TokenPhrase.colors(more_colors = nil)
100
+ * TokenPhrase.patterns(more_patterns = nil)
101
+ * TokenPhrase.nouns(more_nouns = nil)
102
+
103
+ Each of these dictionary methods accept an array as an argument that will merge the existing dictionary with your array
104
+
105
+ ```ruby
106
+ your_patterns = TokenPhrase.patterns %w(magic-eye)
107
+ TokenPhrase.generate :patterns => your_patterns
108
+ => "awesome-mauve-magic-eye-giraffe"
109
+ ```
20
110
 
21
- TODO: Write usage instructions here
22
111
 
23
112
  ## Contributing
24
113
 
@@ -1,3 +1,3 @@
1
1
  module TokenPhrase
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/token_phrase.rb CHANGED
@@ -6,32 +6,32 @@ module TokenPhrase
6
6
  Patterns = %w(striped checked spotted polka-dotted plaid wavy houndstooth argyle glossy matte pinstriped)
7
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
8
 
9
- def self.adjectives
10
- TokenPhrase::Adjectives
9
+ def self.adjectives(more_adjectives = nil)
10
+ more_adjectives.nil? ? TokenPhrase::Adjectives : TokenPhrase::Adjectives | more_adjectives
11
11
  end
12
12
 
13
- def self.colors
14
- TokenPhrase::Colors
13
+ def self.colors(more_colors = nil)
14
+ more_colors.nil? ? TokenPhrase::Colors : TokenPhrase::Colors | more_colors
15
15
  end
16
16
 
17
- def self.patterns
18
- TokenPhrase::Patterns
17
+ def self.patterns(more_patterns = nil)
18
+ more_patterns.nil? ? TokenPhrase::Patterns : TokenPhrase::Patterns | more_patterns
19
19
  end
20
20
 
21
- def self.nouns
22
- TokenPhrase::Nouns
21
+ def self.nouns(more_nouns = nil)
22
+ more_nouns.nil? ? TokenPhrase::Nouns : TokenPhrase::Nouns | more_nouns
23
23
  end
24
24
 
25
- def self.generate(separator = nil, parts = {})
25
+ def self.generate(separator = nil, dictionaries = {})
26
26
  if separator.is_a?(Hash)
27
- parts = separator
27
+ dictionaries = separator
28
28
  separator = nil
29
29
  end
30
- parts[:adjectives] ||= TokenPhrase::Adjectives
31
- parts[:colors] ||= TokenPhrase::Colors
32
- parts[:patterns] ||= TokenPhrase::Patterns
33
- parts[:nouns] ||= TokenPhrase::Nouns
34
- phrase = [parts[:adjectives].sample, parts[:colors].sample, parts[:patterns].sample, parts[:nouns].sample].join('-')
30
+ dictionaries[:adjectives] ||= TokenPhrase::Adjectives
31
+ dictionaries[:colors] ||= TokenPhrase::Colors
32
+ dictionaries[:patterns] ||= TokenPhrase::Patterns
33
+ dictionaries[:nouns] ||= TokenPhrase::Nouns
34
+ phrase = [dictionaries[:adjectives].sample, dictionaries[:colors].sample, dictionaries[:patterns].sample, dictionaries[:nouns].sample].join('-')
35
35
  phrase.gsub!(/-/, separator) unless separator.nil?
36
36
  return phrase
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: token_phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: