Class: GameWords::Generator
- Inherits:
-
Object
- Object
- GameWords::Generator
- Defined in:
- lib/game_words.rb
Instance Method Summary collapse
- #game_categories(game) ⇒ Object
- #games ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
- #words(game, category = nil) ⇒ Object
Constructor Details
#initialize ⇒ Generator
8 9 10 |
# File 'lib/game_words.rb', line 8 def initialize @game_words = YAML.load_file(WORDS_PATH) end |
Instance Method Details
#game_categories(game) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/game_words.rb', line 16 def game_categories(game) return [] unless is_a_valid_game?(game) game_words = @game_words[game] game_words.keys end |
#games ⇒ Object
12 13 14 |
# File 'lib/game_words.rb', line 12 def games @game_words.keys end |
#words(game, category = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/game_words.rb', line 23 def words(game, category = nil) return [] unless is_a_valid_game?(game) return [] unless category.nil? || is_a_valid_game_category?(game, category) words = @game_words[game][category] return words if words all_words = [] @game_words[game].keys.each do |category| all_words += @game_words[game][category] end all_words end |