game_words 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +12 -0
- data/assets/game_words/game_words.yaml +4748 -0
- data/game_words.gemspec +23 -0
- data/lib/game_words/version.rb +3 -0
- data/lib/game_words.rb +51 -0
- data/spec/lib/generator_spec.rb +167 -0
- data/spec/spec_helper.rb +1 -0
- metadata +101 -0
data/game_words.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'game_words/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'game_words'
|
8
|
+
spec.version = GameWords::VERSION
|
9
|
+
spec.authors = ['Nick Aschenbach']
|
10
|
+
spec.email = ['nick.aschenbach@gmail.com']
|
11
|
+
spec.summary = %q{Find words for pictionary, catchphrase, charades and holidays}
|
12
|
+
spec.homepage = 'https://github.com/nick-aschenbach/game-words'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
23
|
+
end
|
data/lib/game_words.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'game_words/version'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module GameWords
|
5
|
+
WORDS_PATH = File.join(File.dirname(__dir__), 'assets', 'game_words', 'game_words.yaml')
|
6
|
+
|
7
|
+
class Generator
|
8
|
+
def initialize
|
9
|
+
@game_words = YAML.load_file(WORDS_PATH)
|
10
|
+
end
|
11
|
+
|
12
|
+
def games
|
13
|
+
@game_words.keys
|
14
|
+
end
|
15
|
+
|
16
|
+
def game_categories(game)
|
17
|
+
return [] unless is_a_valid_game?(game)
|
18
|
+
|
19
|
+
game_words = @game_words[game]
|
20
|
+
game_words.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
def words(game, category = nil)
|
24
|
+
return [] unless is_a_valid_game?(game)
|
25
|
+
return [] unless category.nil? || is_a_valid_game_category?(game, category)
|
26
|
+
|
27
|
+
words = @game_words[game][category]
|
28
|
+
return words if words
|
29
|
+
|
30
|
+
all_words = []
|
31
|
+
@game_words[game].keys.each do |category|
|
32
|
+
all_words += @game_words[game][category]
|
33
|
+
end
|
34
|
+
all_words
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def is_a_valid_game?(game)
|
40
|
+
return true if @game_words[game]
|
41
|
+
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_a_valid_game_category?(game, category)
|
46
|
+
return true if @game_words[game][category]
|
47
|
+
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GameWords::Generator do
|
4
|
+
describe 'WORDS_PATH' do
|
5
|
+
it 'defines a root path for the game words' do
|
6
|
+
expect { GameWords::WORDS_PATH }.not_to raise_error
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.new' do
|
11
|
+
subject { GameWords::Generator.new }
|
12
|
+
|
13
|
+
it 'loads the words YAML file' do
|
14
|
+
expect(YAML).to receive(:load_file).with(GameWords::WORDS_PATH)
|
15
|
+
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#games' do
|
21
|
+
subject { GameWords::Generator.new.games }
|
22
|
+
|
23
|
+
it 'lists the available games' do
|
24
|
+
expect(subject).to match_array(['catchphrase',
|
25
|
+
'holidays',
|
26
|
+
'pictionary',
|
27
|
+
'charades'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#game_categories' do
|
32
|
+
subject { GameWords::Generator.new.game_categories(game) }
|
33
|
+
|
34
|
+
context 'catchphrase' do
|
35
|
+
let(:game) { 'catchphrase' }
|
36
|
+
|
37
|
+
it 'lists catchphrase categories' do
|
38
|
+
expect(subject).to match_array(['easy',
|
39
|
+
'medium',
|
40
|
+
'hard',
|
41
|
+
'animals',
|
42
|
+
'food',
|
43
|
+
'travel',
|
44
|
+
'people',
|
45
|
+
'household'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context 'holidays' do
|
49
|
+
let(:game) { 'holidays' }
|
50
|
+
|
51
|
+
it 'lists the holiday categories' do
|
52
|
+
expect(subject).to match_array(['halloween',
|
53
|
+
'christmas',
|
54
|
+
'independence',
|
55
|
+
'thanksgiving',
|
56
|
+
'christmassong',
|
57
|
+
'valentinesaying',
|
58
|
+
'valentinesong',
|
59
|
+
'valentineword',
|
60
|
+
'newyears',
|
61
|
+
'spring'])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
context 'pictionary' do
|
65
|
+
let(:game) { 'pictionary' }
|
66
|
+
|
67
|
+
it 'lists the pictionary categories' do
|
68
|
+
expect(subject).to match_array(['easy',
|
69
|
+
'medium',
|
70
|
+
'difficult',
|
71
|
+
'hard',
|
72
|
+
'idioms',
|
73
|
+
'characters',
|
74
|
+
'movies'])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context 'charades' do
|
78
|
+
let(:game) { 'charades' }
|
79
|
+
|
80
|
+
it 'lists the charades categories' do
|
81
|
+
expect(subject).to match_array(['easy',
|
82
|
+
'medium',
|
83
|
+
'difficult',
|
84
|
+
'hard',
|
85
|
+
'actions'])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context 'undefined game category' do
|
89
|
+
let(:game) { 'foosball' }
|
90
|
+
|
91
|
+
it 'returns an empty array' do
|
92
|
+
expect(subject).to match_array([])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#words' do
|
98
|
+
subject { GameWords::Generator.new.words(game, category) }
|
99
|
+
|
100
|
+
let(:words) {
|
101
|
+
{
|
102
|
+
'game1' => {
|
103
|
+
'cat1' => %w[word1 word2],
|
104
|
+
'cat2' => %w[word3]
|
105
|
+
},
|
106
|
+
'game2' => {
|
107
|
+
'cat3' => %w[word4]
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
before do
|
113
|
+
allow(YAML).to receive(:load_file).and_return(words)
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when the category is specified' do
|
117
|
+
let(:game) { 'game2' }
|
118
|
+
|
119
|
+
context 'when the category exists' do
|
120
|
+
let(:category) { 'cat3' }
|
121
|
+
|
122
|
+
it 'only shows the words for that category' do
|
123
|
+
expect(subject).to match_array(%w[word4])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when the category does not exist' do
|
128
|
+
let(:category) { 'blah' }
|
129
|
+
|
130
|
+
it 'returns an empty array' do
|
131
|
+
expect(subject).to eq([])
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when the category is not specified' do
|
137
|
+
let(:game) { 'game1' }
|
138
|
+
let(:category) { nil }
|
139
|
+
|
140
|
+
it 'shows all of the words for all categories for that game' do
|
141
|
+
expect(subject).to match_array(%w[word1 word2 word3])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'unhappy paths' do
|
146
|
+
context 'when the game does not exist' do
|
147
|
+
let(:game) { 'foo' }
|
148
|
+
let(:category) { 'cat1' }
|
149
|
+
|
150
|
+
it 'returns an empty array' do
|
151
|
+
expect(subject).to eq([])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when the game exists' do
|
156
|
+
let(:game) { 'game1' }
|
157
|
+
|
158
|
+
context 'but the category does not exist' do
|
159
|
+
let(:category) { 'bar' }
|
160
|
+
it 'returns an empty array' do
|
161
|
+
expect(subject).to eq([])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'game_words'
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: game_words
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Aschenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- nick.aschenbach@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-gemset"
|
64
|
+
- ".ruby-version"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- assets/game_words/game_words.yaml
|
70
|
+
- game_words.gemspec
|
71
|
+
- lib/game_words.rb
|
72
|
+
- lib/game_words/version.rb
|
73
|
+
- spec/lib/generator_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
homepage: https://github.com/nick-aschenbach/game-words
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Find words for pictionary, catchphrase, charades and holidays
|
99
|
+
test_files:
|
100
|
+
- spec/lib/generator_spec.rb
|
101
|
+
- spec/spec_helper.rb
|