cryptozoologist 3.1.0 → 3.2.0
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +13 -140
- data/lib/cryptozoologist.rb +8 -0
- data/lib/cryptozoologist/dictionaries.rb +17 -2
- data/lib/cryptozoologist/dictionaries/clothing.rb +1 -21
- data/lib/cryptozoologist/dictionaries/colors/paint.rb +0 -3
- data/lib/cryptozoologist/dictionaries/people/first_name.rb +13 -0
- data/lib/cryptozoologist/dictionaries/people/last_name.rb +13 -0
- data/lib/cryptozoologist/dictionaries/states.rb +60 -0
- data/lib/cryptozoologist/dictionary.rb +12 -0
- data/lib/cryptozoologist/generator.rb +69 -4
- data/lib/cryptozoologist/version.rb +1 -1
- data/spec/cryptozoologist/dictionaries_spec.rb +8 -2
- data/spec/cryptozoologist/dictionary_spec.rb +1 -1
- data/spec/cryptozoologist/generator_spec.rb +45 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -3
@@ -30,8 +30,20 @@ module Cryptozoologist
|
|
30
30
|
Dictionaries.addresses
|
31
31
|
end
|
32
32
|
|
33
|
+
def states
|
34
|
+
Dictionaries.states
|
35
|
+
end
|
36
|
+
|
33
37
|
def cities
|
34
38
|
Dictionaries.cities
|
35
39
|
end
|
40
|
+
|
41
|
+
def first_name
|
42
|
+
Dictionaries.first_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def last_name
|
46
|
+
Dictionaries.last_name
|
47
|
+
end
|
36
48
|
end
|
37
49
|
end
|
@@ -4,7 +4,7 @@ module Cryptozoologist
|
|
4
4
|
|
5
5
|
# Generates sentence_count sentences, ranging in length from 10-16 words,
|
6
6
|
# using the dictionaries from your config.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
def lorem(sentence_count)
|
9
9
|
sentences = []
|
10
10
|
order = Cryptozoologist.configuration.order
|
@@ -29,7 +29,7 @@ module Cryptozoologist
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Generates a string using the dictionaries and delimiter from your config.
|
32
|
-
#
|
32
|
+
#
|
33
33
|
def random
|
34
34
|
string = ""
|
35
35
|
order = Cryptozoologist.configuration.order
|
@@ -39,7 +39,7 @@ module Cryptozoologist
|
|
39
39
|
string += "#{compound_word}"
|
40
40
|
|
41
41
|
unless library == Cryptozoologist.configuration.order.last
|
42
|
-
string += "#{Cryptozoologist.configuration.delimiter}"
|
42
|
+
string += "#{Cryptozoologist.configuration.delimiter}"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -56,6 +56,25 @@ module Cryptozoologist
|
|
56
56
|
"#{number} #{street} #{Dictionary.addresses.sample}"
|
57
57
|
end
|
58
58
|
|
59
|
+
# Generates a string for a U.S. state name which is partially replaced by
|
60
|
+
# alliterative words from other dictionaries (e.g. "Oregon" can become "Oregoose" or "Orabbit")
|
61
|
+
# Does not respect config exclusions
|
62
|
+
# Note: optional arguments desired_library is an String containing the single replacement word of your choice
|
63
|
+
# desired_state is a String of the specific state name of your choice
|
64
|
+
#{}`desired_replace_index` is an integer that allows you to specify whether the first
|
65
|
+
#or second word will be replaced, or in the case of a one-word state - which letter is replaced
|
66
|
+
def state(desired_state, desired_library, desired_replace_index)
|
67
|
+
libraries = desired_library || [:animals, :clothing, :colors]
|
68
|
+
state_name = desired_state || Dictionary.states.sample
|
69
|
+
has_two_words = state_name.index(" ")
|
70
|
+
|
71
|
+
if has_two_words
|
72
|
+
handle_two_word(state_name, libraries, desired_replace_index)
|
73
|
+
else
|
74
|
+
handle_one_word(state_name, libraries, desired_replace_index)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
59
78
|
def city
|
60
79
|
exclude = Cryptozoologist.configuration.exclude
|
61
80
|
cities_words = Cryptozoologist::Cities::Words.list
|
@@ -67,10 +86,56 @@ module Cryptozoologist
|
|
67
86
|
"#{one_word_animals.sample.capitalize}#{city_labels.sample}"
|
68
87
|
end
|
69
88
|
|
89
|
+
def full_name
|
90
|
+
first_name = Cryptozoologist::Dictionaries::People::FirstName.list.sample
|
91
|
+
last_name = Cryptozoologist::Dictionaries::People::LastName.list.sample
|
92
|
+
|
93
|
+
"#{first_name} #{last_name}#{one_word_animals.sample.capitalize}"
|
94
|
+
end
|
95
|
+
|
70
96
|
private
|
71
97
|
|
98
|
+
#completely replaces one random word from the state with an alliterative word from libraries
|
99
|
+
def handle_two_word(state_name, libraries, desired_replace_index)
|
100
|
+
base_state_words = state_name.split(" ")
|
101
|
+
replace_index = desired_replace_index || rand(0..1)
|
102
|
+
base_state_words[replace_index] = get_alliteration(libraries, base_state_words[replace_index][0]).capitalize
|
103
|
+
return base_state_words.join(" ")
|
104
|
+
end
|
105
|
+
|
106
|
+
#selects a random key_letter from state_name, and finds an alliterative word from libraries for replacement
|
107
|
+
def handle_one_word(state_name, libraries, desired_replace_index)
|
108
|
+
key_letter_index = desired_replace_index || rand(0...state_name.length-1)
|
109
|
+
insert_word = get_alliteration(libraries, state_name[key_letter_index]).downcase
|
110
|
+
|
111
|
+
#if the randomly selected word from libraries has more letters than the substring from key_letter_index to state_name.length
|
112
|
+
#completely replace that substring
|
113
|
+
if insert_word.length > (state_name.length - key_letter_index) && key_letter_index > 0
|
114
|
+
final_word = state_name.slice(0...key_letter_index) + insert_word
|
115
|
+
#otherwise, replace only the key_letter with the entire random word from libraries
|
116
|
+
else
|
117
|
+
state_name[key_letter_index] = insert_word
|
118
|
+
final_word = state_name
|
119
|
+
end
|
120
|
+
|
121
|
+
final_word.capitalize
|
122
|
+
end
|
123
|
+
|
124
|
+
#finds a word from libraries that begins with key_letter
|
125
|
+
def get_alliteration(libraries, key_letter)
|
126
|
+
return libraries if libraries.is_a? String #this is the case for testing
|
127
|
+
replacement_options = Dictionary.send(libraries.sample).select { |word| word[0] == key_letter || word[0] == key_letter.downcase }
|
128
|
+
|
129
|
+
#default to :animals library if the randomly-selected library has no words that begin with key_letter
|
130
|
+
if replacement_options.empty?
|
131
|
+
replacement_options = Dictionary.send(:animals).select { |word| word[0] == key_letter || word[0] == key_letter.downcase }
|
132
|
+
end
|
133
|
+
|
134
|
+
replacement_options.sample
|
135
|
+
end
|
136
|
+
|
72
137
|
def one_word_animals
|
73
138
|
Dictionary.animals.select {|animal| animal.split(' ').count == 1}
|
74
139
|
end
|
75
140
|
end
|
76
|
-
end
|
141
|
+
end
|
@@ -14,9 +14,10 @@ describe Cryptozoologist::Dictionaries do
|
|
14
14
|
}
|
15
15
|
}
|
16
16
|
|
17
|
-
dictionaries = {
|
17
|
+
dictionaries = {
|
18
18
|
"clothing": Cryptozoologist::Dictionaries::Clothing,
|
19
|
-
"quantity": Cryptozoologist::Dictionaries::Quantity
|
19
|
+
"quantity": Cryptozoologist::Dictionaries::Quantity,
|
20
|
+
"states": Cryptozoologist::Dictionaries::States
|
20
21
|
}
|
21
22
|
|
22
23
|
context '#libraries' do
|
@@ -29,6 +30,11 @@ describe Cryptozoologist::Dictionaries do
|
|
29
30
|
keys = Cryptozoologist::Dictionaries.library[:colors].keys
|
30
31
|
expect(keys.length).to eq(2)
|
31
32
|
end
|
33
|
+
|
34
|
+
it 'contains states' do
|
35
|
+
states = Cryptozoologist::Dictionaries.states
|
36
|
+
expect(states.length).to eq(50)
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
subdictionaries.each do |type, subdictionary|
|
@@ -5,7 +5,7 @@ describe Cryptozoologist::Dictionary do
|
|
5
5
|
@dictionary = Cryptozoologist::Dictionary
|
6
6
|
end
|
7
7
|
|
8
|
-
lists = [:animals, :colors, :clothing, :quantity]
|
8
|
+
lists = [:animals, :colors, :clothing, :quantity, :states, :first_name, :last_name]
|
9
9
|
|
10
10
|
context 'word lists' do
|
11
11
|
lists.each do |list|
|
@@ -77,6 +77,25 @@ describe Cryptozoologist do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
context '#state' do
|
81
|
+
|
82
|
+
it 'handles a one word state' do
|
83
|
+
expect(Cryptozoologist.state("Washington", "Seal", 2)).to eq('Wasealhington')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'handles a two word state' do
|
87
|
+
expect(Cryptozoologist.state("North Dakota", "Necktie", 0)).to eq('Necktie Dakota')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'handles a replacement word longer than the remainder of the state name' do
|
91
|
+
expect(Cryptozoologist.state("California", "Iguana", 8)).to eq('Californiguana')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'handles a replacement word shorter than the remainder of the state name' do
|
95
|
+
expect(Cryptozoologist.state("Oregon", "Rat", 1)).to eq('Orategon')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
80
99
|
context '#city' do
|
81
100
|
before do
|
82
101
|
@city = Cryptozoologist.city
|
@@ -104,4 +123,30 @@ describe Cryptozoologist do
|
|
104
123
|
expect(has_city).to be true
|
105
124
|
end
|
106
125
|
end
|
126
|
+
|
127
|
+
context '#full_name' do
|
128
|
+
before do
|
129
|
+
@person = Cryptozoologist.full_name
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should return datatype string' do
|
133
|
+
expect(@person).to be_instance_of(String)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should contain an animal' do
|
137
|
+
has_animal = false
|
138
|
+
Cryptozoologist::Dictionary.animals.each do |animal|
|
139
|
+
has_animal = true if @person.downcase.include?(animal)
|
140
|
+
end
|
141
|
+
expect(has_animal).to be true
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should contain an adjective for the animal' do
|
145
|
+
has_adjective = false
|
146
|
+
Cryptozoologist::Dictionaries::People::LastName.list.each do |adjective|
|
147
|
+
has_adjective = true if @person.include?(adjective)
|
148
|
+
end
|
149
|
+
expect(has_adjective).to be true
|
150
|
+
end
|
151
|
+
end
|
107
152
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptozoologist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liz Abinante
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,8 +105,11 @@ files:
|
|
105
105
|
- lib/cryptozoologist/dictionaries/colors/paint.rb
|
106
106
|
- lib/cryptozoologist/dictionaries/colors/web_safe.rb
|
107
107
|
- lib/cryptozoologist/dictionaries/filler.rb
|
108
|
+
- lib/cryptozoologist/dictionaries/people/first_name.rb
|
109
|
+
- lib/cryptozoologist/dictionaries/people/last_name.rb
|
108
110
|
- lib/cryptozoologist/dictionaries/punctuation.rb
|
109
111
|
- lib/cryptozoologist/dictionaries/quantity.rb
|
112
|
+
- lib/cryptozoologist/dictionaries/states.rb
|
110
113
|
- lib/cryptozoologist/dictionary.rb
|
111
114
|
- lib/cryptozoologist/errors.rb
|
112
115
|
- lib/cryptozoologist/generator.rb
|
@@ -148,4 +151,3 @@ test_files:
|
|
148
151
|
- spec/cryptozoologist/generator_spec.rb
|
149
152
|
- spec/cryptozoologist_spec.rb
|
150
153
|
- spec/spec_helper.rb
|
151
|
-
has_rdoc:
|