Class: FandomWord::FandomRandomizer
- Inherits:
-
Object
- Object
- FandomWord::FandomRandomizer
- Includes:
- Singleton
- Defined in:
- lib/fandom_word.rb
Overview
Provides singleton interface with fandom word catalog to allow retrieval of random words, random words based on fandoms and list of all available fandoms
Instance Method Summary collapse
-
#available_fandoms ⇒ Object
Returns the list of fandoms (categories).
-
#initialize ⇒ FandomRandomizer
constructor
Caches word catalog into memory for performance.
-
#random_word(fandom_name_or_names = random_fandom) ⇒ String
Returns random word from any fandom in catalog.
Constructor Details
#initialize ⇒ FandomRandomizer
Caches word catalog into memory for performance
36 37 38 |
# File 'lib/fandom_word.rb', line 36 def initialize load_word_catalog end |
Instance Method Details
#available_fandoms ⇒ Object
Returns the list of fandoms (categories)
59 60 61 |
# File 'lib/fandom_word.rb', line 59 def available_fandoms @catalog.fandoms end |
#random_word(fandom_name_or_names = random_fandom) ⇒ String
Returns random word from any fandom in catalog. Fandom category can be specified.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fandom_word.rb', line 44 def random_word(fandom_name_or_names = random_fandom) fandom_name = case fandom_name_or_names when Array validate_fandom_list fandom_name_or_names random_fandom_name_from fandom_name_or_names when String fandom_name_or_names else raise ArgumentError, "Argument must be [Array, String] not #{fandom_name_or_names.class}" end fetch_fandom fandom_name end |