Class: Dmcli::SpellList

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

Overview

SpellList Stores a list of Spell objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpellList

Returns a new instance of SpellList.



9
10
11
# File 'lib/dmcli/spell_list.rb', line 9

def initialize
  @spells = []
end

Instance Attribute Details

#spellsObject (readonly)

Returns the value of attribute spells.



7
8
9
# File 'lib/dmcli/spell_list.rb', line 7

def spells
  @spells
end

Instance Method Details

#add(spell) ⇒ Object



13
14
15
# File 'lib/dmcli/spell_list.rb', line 13

def add(spell)
  @spells.push(spell)
end

#listObject



21
22
23
24
25
26
27
# File 'lib/dmcli/spell_list.rb', line 21

def list
  puts "#{"Name".ljust(35)} #{"Class".ljust(13)} #{"Lvl".ljust(4)} #{"Range".ljust(30)} #{"Duration".ljust(45)} Effect"
  puts "----------------------------------------------------------------------------------------------------------------------------------------------------------"
  @spells.each do |spell|
    puts spell.to_s
  end
end

#sortObject



17
18
19
# File 'lib/dmcli/spell_list.rb', line 17

def sort
  @spells.sort_by! { |spell| [spell.spell_level, spell.spell_class, spell.name] }
end