class RowlingsWizard::Spellbook

Attributes

spells[R]

Public Class Methods

new() click to toggle source
# File lib/rowlings_wizard/spellbook.rb, line 5
def initialize
  @spells = spells_data
end

Public Instance Methods

random_spell() click to toggle source
# File lib/rowlings_wizard/spellbook.rb, line 17
def random_spell
  spell_name = spells.keys.shuffle.first
  build_spell(spell_name)
end
spell(spell_name) click to toggle source
# File lib/rowlings_wizard/spellbook.rb, line 9
def spell(spell_name)
  if spells[spell_name].nil?
    "Spell \"#{spell_name}\" not found in spellbook."
  else
    build_spell(spell_name)
  end
end

Private Instance Methods

build_spell(spell_name) click to toggle source
# File lib/rowlings_wizard/spellbook.rb, line 34
def build_spell(spell_name)
  spell = spells[spell_name]
  spell[:name] = spell_name
  spell
end
spells_data() click to toggle source
# File lib/rowlings_wizard/spellbook.rb, line 24
def spells_data
  HashWithIndifferentAccess.new(
    YAML.load(
      File.read(
        File.expand_path('../spells.yml', __FILE__)
      )
    )
  )
end