cryptozoologist 1.3.1 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd5e660c2e2933d44cc36660e28cbf7b020e22a7
4
- data.tar.gz: a14810a76aa03107faacd3d8b4802efacb6bd1a7
3
+ metadata.gz: 9411dfc9037961beb292b84b3a010911a4df12d2
4
+ data.tar.gz: 7516103b3806e76b01be5ec74f482939aab0e06d
5
5
  SHA512:
6
- metadata.gz: 00d2393f1aa24946ccbe019305e6d2b477252cb7c31b1df764caf708e825a568adc9f3788c1b574b9e78a9a19fbe004b9cc211080d5df95f987534430ef70333
7
- data.tar.gz: fff4b36b58fd513a2db9f8e8089ec7f1d401db9fc293f1275ff718047383ca65e187577633e1281d3ac0cfad9008693f4190f92468fd8bc1ecad0c1d481d2620
6
+ metadata.gz: 0061af7c09ba38a8f4ffdfa25ba5a196f6dc3ff0600b6b6a179507cf338bf3fc078e72a6b25b1175dc83f71ec43198c6b699a5a52b4295975bfb987823221a50
7
+ data.tar.gz: 7b56a87a18854f844b9df9f51dee3ed4abb40123e6642e0374532df171afa37fa5412cdf6ef93a11c4365a9e18120378c1d760fb7f808859d28a9a748687827f
data/README.md CHANGED
@@ -2,11 +2,7 @@
2
2
 
3
3
  _Cryptozoologist is a fun little gem written as part of the [Gem guide](https://github.com/feministy/gem-guide) project._
4
4
 
5
- Cryptozoologist generates random strings from animal, clothing item, and color pairings. You could get something like "orange-clownfish-turtleneck" or "magenta-three-toed-sloth-shoe-horn". It's fun and silly - it's also very simple, which is why it is used as an example for the Gem guide project.
6
-
7
- This gem is still in active devemopment; complete documentation _will be added_ as the gem (and the Gem guide) progress!
8
-
9
- _(No, really, it will be added: it's part of the guide!)_
5
+ Cryptozoologist generates random strings from animal, clothing item, and color pairings. You could get something like "orange-clownfish-turtleneck" or "magenta-three-toed-sloth-shoe-horn". It's fun and silly, because why not?
10
6
 
11
7
  ## Installation
12
8
 
@@ -26,68 +22,87 @@ Or install it yourself as:
26
22
 
27
23
  ## Usage
28
24
 
29
- Right now, this gem doesn't do much of anything except over architect a series of word lists.
25
+ `Cryptozoologist.generate` method will return a string separated by `-` containing: a color, an animal, and an item of clothing.
30
26
 
31
- **Available word lists**
27
+ Example:
32
28
 
33
- - colors
34
- - animals
35
- - clothing
36
- - quantity
29
+ ```ruby
30
+ Cryptozoologist.generate # => 'steel-blue-tang-flak-jacket'
31
+ Cryptozoologist.generate # => 'blanched-almond-mandrill-headscarf'
32
+ Cryptozoologist.generate # => 'frozen-in-time-cockroach-bracelet'
33
+ Cryptozoologist.generate # => 'medium-sea-green-lobster-coat'
34
+ Cryptozoologist.generate # => 'blue-flying-squirrel-trench-coat'
35
+ Cryptozoologist.generate # => 'thistle-toucan-formal-wear'
36
+ Cryptozoologist.generate # => 'aquamarine-lemming-white-tie'
37
+ Cryptozoologist.generate # => 'tomato-cerberus-sweatshirt'
38
+ Cryptozoologist.generate # => 'forest-green-wasp-getup'
39
+ ```
37
40
 
38
- **Configuration options**
41
+ ### Generate a random color, animal, clothing item, or measure of quantity
39
42
 
40
- Exclude:
43
+ These dictionaries will also follow your configuration settings (see below), _except for your delimeter_ (the delimeter is not used here).
41
44
 
42
- - animals:
43
- - `:common`, `:mythical`
44
- - colors:
45
- - `:paint`, `:web`
45
+ ```ruby
46
+ Cryptozoologist::Dictionary.animals.sample # => 'sun bear'
47
+ Cryptozoologist::Dictionary.clothing.sample # => 'fedora'
48
+ Cryptozoologist::Dictionary.colors.sample # => 'light pink'
49
+ Cryptozoologist::Dictionary.quantity.sample # => 'limitless'
50
+ ```
46
51
 
47
- *Note:* you can only exclude one of each or you won't have any words in your list!
52
+ ## Configuration
48
53
 
49
- **Example**
54
+ Configuration blocks take the following options:
50
55
 
51
56
  ```ruby
52
57
  Cryptozoologist.configure do |config|
53
- config.exclude = [:common]
58
+ config.exclude = []
59
+ config.include = []
60
+ config.order = []
61
+ config.delimeter = ''
54
62
  end
55
-
56
- dictionary = Cryptozoologist::Dictionary.new
57
- animals = dictionary.animals
58
- animals.sample # => "crumple horned snorkack"
59
63
  ```
60
64
 
61
- **Get a random animal**
65
+ - `exclude` (array of symbols) allows you to exclude dictionary subtypes; defaults to no exclusions
66
+ - `include` (array of symbols) allows you to include optional dictionaries; defaults to no inclusions
67
+ - `order` (array of symbols) allows you to change the word order; defaults to animal-color-clothing
68
+ - `delimeter` (string) allows you to specify a delimeter; defaults to `-`
62
69
 
63
- ```ruby
64
- dictionary = Cryptozoologist::Dictionary.new
65
- animals = dictionary.animals
66
- animals.sample # => "sun bear"
67
- ```
70
+ ### Configuration options
68
71
 
69
- **Get a random color**
72
+ **Include (`config.include`, `[]`):**
70
73
 
71
- ```ruby
72
- dictionary = Cryptozoologist::Dictionary.new
73
- colors = dictionary.colors
74
- colors.sample # => "pink"
75
- ```
74
+ - if you include quantity, it will be added to the front of your generated string
75
+ - `:quantity`
76
76
 
77
- **Get a random measure of quantity**
77
+ **Exclude (`config.exclude`, `[]`):**
78
78
 
79
- ```ruby
80
- dictionary = Cryptozoologist::Dictionary.new
81
- quantity = dictionary.quantity
82
- quantity.sample # => "limitless"
83
- ```
79
+ - animals (1 of 2 allowed):
80
+ - `:common`, `:mythical`
81
+ - colors (1 of 2 allowed):
82
+ - `:paint`, `:web`
84
83
 
85
- **Get a random item of clothing**
84
+ **Order (`config.order`, `[]`): **
86
85
 
87
- ```ruby
88
- dictionary = Cryptozoologist::Dictionary.new
89
- clothing = dictionary.clothing
90
- clothing.sample # => "suspenders"
91
- ```
86
+ - **must provide all 3 keys** as an array in the order in which you want words to appear
87
+ - `[:animals, :colors, :clothing]`
88
+
89
+ **Delimeter (`config.delimeter`, `''`):**
90
+
91
+ - defaults to `'-'`
92
+ - any string is valid
92
93
 
94
+ #### Example
93
95
 
96
+ ```ruby
97
+ Cryptozoologist.configure do |config|
98
+ config.exclude = [:common]
99
+ config.include = [:quantity]
100
+ config.order = [:colors, :animals, :clothing]
101
+ config.delimeter = '_'
102
+ end
103
+
104
+ Cryptozoologist.generate # => 'masses_yellow_zombie_shrug'
105
+ Cryptozoologist.generate # => 'gazillions_polar_drift_goblin_umbrella'
106
+ Cryptozoologist.generate # => 'wide_orange_cynocephalus_helmet'
107
+ Cryptozoologist.generate # => 'some_light_pink_moke_fedora'
108
+ ```
@@ -25,7 +25,26 @@ module Cryptozoologist
25
25
  yield(configuration)
26
26
  end
27
27
 
28
- protected
28
+ def self.generate
29
+ string = ""
30
+ order = @configuration.order
31
+
32
+ order.unshift(:quantity) if @configuration.include_quantity?
33
+
34
+ order.each do |library|
35
+ word = Dictionary.send(library).sample
36
+ compound_word = word.split(' ').join(@configuration.delimeter)
37
+ string += "#{compound_word}"
38
+
39
+ unless library == @configuration.order.last
40
+ string += "#{@configuration.delimeter}"
41
+ end
42
+ end
43
+
44
+ string
45
+ end
46
+
47
+ protected
29
48
  def self.subdictionaries
30
49
  Dictionaries.library
31
50
  end
@@ -1,9 +1,33 @@
1
1
  module Cryptozoologist
2
2
  class Configuration
3
- attr_reader :exclude
3
+ attr_reader :exclude, :delimeter, :order, :include
4
4
 
5
5
  def initialize
6
6
  @exclude = []
7
+ @delimeter = "-"
8
+ @order = [:colors, :animals, :clothing]
9
+ @include = []
10
+ end
11
+
12
+ def order=(list)
13
+ raise Errors::Configuration, "Order must be an array" unless list.is_a?(Array)
14
+ raise Errors::Configuration, "Order must contain 3 items" unless list.length == 3
15
+ invalid_keys = list.select { |e| !valid_order.include?(e) }
16
+ raise Errors::Configuration, "Invalid order setting provided: #{invalid_keys}" unless invalid_keys.empty?
17
+
18
+ @order = list
19
+ end
20
+
21
+ def delimeter=(string)
22
+ raise Errors::Configuration, "Delimeter must be a a string" unless string.is_a?(String)
23
+
24
+ @delimeter = string
25
+ end
26
+
27
+ def include=(inclusions)
28
+ raise Errors::Configuration, "Inclusions must be an array" unless inclusions.is_a?(Array)
29
+
30
+ @include = inclusions.select { |e| valid_inclusions.include?(e) }
7
31
  end
8
32
 
9
33
  def exclude=(exclusions)
@@ -12,11 +36,23 @@ module Cryptozoologist
12
36
  @exclude = exclusions.select { |e| valid_exclusions.include?(e) }
13
37
  end
14
38
 
39
+ def include_quantity?
40
+ @include.include?(:quantity)
41
+ end
42
+
15
43
  private
44
+ def valid_order
45
+ [:animals, :colors, :clothing]
46
+ end
47
+
16
48
  def valid_exclusions
17
49
  keys = []
18
50
  Cryptozoologist.subdictionaries.each { |key, value| keys += value.keys }
19
51
  keys
20
52
  end
53
+
54
+ def valid_inclusions
55
+ [:quantity]
56
+ end
21
57
  end
22
58
  end
@@ -1,20 +1,13 @@
1
1
  module Cryptozoologist
2
- class Dictionary
3
- def initialize
4
- @animals = []
5
- @colors = []
6
- end
2
+ module Dictionary
3
+ extend self
7
4
 
8
5
  def animals
9
- @animals if @animals.any?
10
- @animals = Dictionaries.animals
11
- @animals
6
+ Dictionaries.animals
12
7
  end
13
8
 
14
9
  def colors
15
- @colors if @colors.any?
16
- @colors = Dictionaries.colors
17
- @colors
10
+ Dictionaries.colors
18
11
  end
19
12
 
20
13
  def clothing
@@ -1,3 +1,3 @@
1
1
  module Cryptozoologist
2
- VERSION = "1.3.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,10 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe Cryptozoologist::Configuration do
4
+ before do
5
+ Cryptozoologist.reset
6
+ end
7
+
4
8
  context 'without configuration block' do
5
9
  it 'returns an empty Configuration' do
6
10
  expect(Cryptozoologist.configuration).to be_instance_of(Cryptozoologist::Configuration)
@@ -25,4 +29,97 @@ describe Cryptozoologist::Configuration do
25
29
  }.to raise_error(Cryptozoologist::Errors::Configuration)
26
30
  end
27
31
  end
32
+
33
+ context 'inclusions' do
34
+ it 'filters out invalid inclusions' do
35
+ Cryptozoologist.configure do |config|
36
+ config.include = [:tacos]
37
+ end
38
+
39
+ expect(Cryptozoologist.configuration.include).to eq([])
40
+ end
41
+
42
+ it 'requires an array' do
43
+ expect {
44
+ Cryptozoologist.configure do |config|
45
+ config.include = 1
46
+ end
47
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
48
+ end
49
+
50
+ it 'sets valid inclusions' do
51
+ Cryptozoologist.configure do |config|
52
+ config.include = [:quantity]
53
+ end
54
+
55
+ expect(Cryptozoologist.configuration.include).to eq([:quantity])
56
+ end
57
+ end
58
+
59
+ context '#delimeter' do
60
+ it 'defaults to "-"' do
61
+ expect(Cryptozoologist.generate.match('-')).to be_instance_of(MatchData)
62
+ end
63
+
64
+ it 'requires a string' do
65
+ expect {
66
+ Cryptozoologist.configure do |config|
67
+ config.delimeter = 1
68
+ end
69
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
70
+ end
71
+
72
+ it 'changes the delimeter when provided' do
73
+ Cryptozoologist.configure do |config|
74
+ config.delimeter ='$'
75
+ end
76
+
77
+ expect(Cryptozoologist.generate.match('$')).to be_instance_of(MatchData)
78
+ end
79
+ end
80
+
81
+ context '#order' do
82
+ it 'defaults to colors, animals, clothing' do
83
+ expect(Cryptozoologist.configuration.order).to eq([:colors, :animals, :clothing])
84
+ end
85
+
86
+ it 'rejects everything if anything invalid is passed' do
87
+ expect {
88
+ Cryptozoologist.configure do |config|
89
+ config.order = [:colors, :animals, :tacos]
90
+ end
91
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
92
+ end
93
+
94
+ it 'rejects everything if fewer than 3 keys are passed' do
95
+ expect {
96
+ Cryptozoologist.configure do |config|
97
+ config.order = [:colors, :animals]
98
+ end
99
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
100
+ end
101
+
102
+ it 'rejects everything if more than 3 keys are passed' do
103
+ expect {
104
+ Cryptozoologist.configure do |config|
105
+ config.order = [:colors, :animals, :clothing, :tacos]
106
+ end
107
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
108
+ end
109
+
110
+ it 'requires an array' do
111
+ expect {
112
+ Cryptozoologist.configure do |config|
113
+ config.order = 1
114
+ end
115
+ }.to raise_error(Cryptozoologist::Errors::Configuration)
116
+ end
117
+
118
+ it 'changes the order of keys' do
119
+ Cryptozoologist.configure do |config|
120
+ config.order = [:clothing, :colors, :animals]
121
+ end
122
+ expect(Cryptozoologist.configuration.order).to eq([:clothing, :colors, :animals])
123
+ end
124
+ end
28
125
  end
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
2
2
 
3
3
  describe Cryptozoologist::Dictionary do
4
4
  before do
5
- @dictionary = Cryptozoologist::Dictionary.new
5
+ @dictionary = Cryptozoologist::Dictionary
6
6
  end
7
7
 
8
8
  lists = [:animals, :colors, :clothing, :quantity]
@@ -14,4 +14,14 @@ describe Cryptozoologist do
14
14
  Cryptozoologist.reset
15
15
  expect(Cryptozoologist.configuration.exclude).to eq([])
16
16
  end
17
+
18
+ context '#generate' do
19
+ it 'returns a string' do
20
+ expect(Cryptozoologist.generate).to be_instance_of(String)
21
+ end
22
+
23
+ it 'returns a string with the delimeter' do
24
+ expect(Cryptozoologist.generate.match('-')).to be_instance_of(MatchData)
25
+ end
26
+ end
17
27
  end
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: 1.3.1
4
+ version: 2.0.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: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -82,8 +82,7 @@ dependencies:
82
82
  version: 0.2.4
83
83
  description: Cryptozoologist generates random strings from animal, clothing item,
84
84
  and color pairings. You could get something like 'orange-clownfish-turtleneck' or
85
- 'magenta-three-toed-sloth-shoe-horn'. It's fun and silly - it's also very simple,
86
- which is why it is used as an example for the Gem guide project.
85
+ 'magenta-three-toed-sloth-shoe-horn'. It's fun and silly, because why not?
87
86
  email:
88
87
  - me@liz.codes
89
88
  executables: []