Class: Dmcli::SpellList
- Inherits:
-
Object
- Object
- Dmcli::SpellList
- Defined in:
- lib/dmcli/spell_list.rb
Overview
SpellList Stores a list of Spell objects
Instance Attribute Summary collapse
-
#spells ⇒ Object
readonly
Returns the value of attribute spells.
Instance Method Summary collapse
- #add(spell) ⇒ Object
-
#initialize ⇒ SpellList
constructor
A new instance of SpellList.
- #list ⇒ Object
- #sort ⇒ Object
Constructor Details
#initialize ⇒ SpellList
Returns a new instance of SpellList.
9 10 11 |
# File 'lib/dmcli/spell_list.rb', line 9 def initialize @spells = [] end |
Instance Attribute Details
#spells ⇒ Object (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 |
#list ⇒ Object
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 |
#sort ⇒ Object
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 |