class GameWords::Generator

Public Class Methods

new() click to toggle source
# File lib/game_words.rb, line 8
def initialize
  @game_words = YAML.load_file(WORDS_PATH)
end

Public Instance Methods

game_categories(game) click to toggle source
# 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() click to toggle source
# File lib/game_words.rb, line 12
def games
  @game_words.keys
end
words(game, category = nil) click to toggle source
# 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

Private Instance Methods

is_a_valid_game?(game) click to toggle source
# File lib/game_words.rb, line 39
def is_a_valid_game?(game)
  return true if @game_words[game]

  false
end
is_a_valid_game_category?(game, category) click to toggle source
# File lib/game_words.rb, line 45
def is_a_valid_game_category?(game, category)
  return true if @game_words[game][category]

  false
end