Class: FandomWord::FandomWordCatalog

Inherits:
Object
  • Object
show all
Defined in:
lib/fandom_word_catalog.rb

Overview

FandomWordCatalog is a catalog holding all words in groups of fandoms.

Instance Method Summary collapse

Constructor Details

#initializeFandomWordCatalog

Returns a new instance of FandomWordCatalog.



4
5
6
# File 'lib/fandom_word_catalog.rb', line 4

def initialize
  @fandoms = {}
end

Instance Method Details

#add_word(new_word, categories) ⇒ Object

Adds a word to a fandom



15
16
17
18
19
20
# File 'lib/fandom_word_catalog.rb', line 15

def add_word(new_word, categories)
  categories.each do |category|
    fandom = fetch_fandom(category)
    fandom << new_word unless fandom.include? new_word
  end
end

#fandomsObject

Returns the list of fandoms (categories)



23
24
25
# File 'lib/fandom_word_catalog.rb', line 23

def fandoms
  @fandoms.keys
end

#fetch_fandom(fandom) ⇒ Object

Returns an array of words associated with the specified fandom. Initializes fandom in catalog if not present.



9
10
11
12
# File 'lib/fandom_word_catalog.rb', line 9

def fetch_fandom(fandom)
  # grab the category if it exists, if not make it empty array
  @fandoms.keys.include?(fandom) ? @fandoms[fandom] : @fandoms[fandom] = []
end