Class: MonsterIndex::Monster
- Inherits:
-
Object
- Object
- MonsterIndex::Monster
- Defined in:
- lib/monster_index/monster.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#ac ⇒ Object
Returns the value of attribute ac.
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#attack ⇒ Object
Returns the value of attribute attack.
-
#hit_dice ⇒ Object
Returns the value of attribute hit_dice.
-
#initiative ⇒ Object
Returns the value of attribute initiative.
-
#name ⇒ Object
Returns the value of attribute name.
-
#size_type ⇒ Object
Returns the value of attribute size_type.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_collection(monster_array) ⇒ Object
- .get_monster(name) ⇒ Object
- .get_names ⇒ Object
- .list ⇒ Object
- .list_some(letter) ⇒ Object
- .view_profile(name) ⇒ Object
Instance Method Summary collapse
- #add_monster_attributes(attributes_hash) ⇒ Object
-
#initialize(monster_hash = {}) ⇒ Monster
constructor
A new instance of Monster.
Constructor Details
#initialize(monster_hash = {}) ⇒ Monster
Returns a new instance of Monster.
6 7 8 9 |
# File 'lib/monster_index/monster.rb', line 6 def initialize(monster_hash = {}) monster_hash.each {|key, value| self.send(("#{key}="), value)} @@all << self end |
Instance Attribute Details
#ac ⇒ Object
Returns the value of attribute ac.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def ac @ac end |
#alignment ⇒ Object
Returns the value of attribute alignment.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def alignment @alignment end |
#attack ⇒ Object
Returns the value of attribute attack.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def attack @attack end |
#hit_dice ⇒ Object
Returns the value of attribute hit_dice.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def hit_dice @hit_dice end |
#initiative ⇒ Object
Returns the value of attribute initiative.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def initiative @initiative end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def name @name end |
#size_type ⇒ Object
Returns the value of attribute size_type.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def size_type @size_type end |
#speed ⇒ Object
Returns the value of attribute speed.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def speed @speed end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/monster_index/monster.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
63 64 65 |
# File 'lib/monster_index/monster.rb', line 63 def self.all @@all end |
.create_from_collection(monster_array) ⇒ Object
11 12 13 14 15 |
# File 'lib/monster_index/monster.rb', line 11 def self.create_from_collection(monster_array) monster_array.each do |monster_hash| self.new(monster_hash) end end |
.get_monster(name) ⇒ Object
59 60 61 |
# File 'lib/monster_index/monster.rb', line 59 def self.get_monster(name) @@all.find {|one| one.name == name} end |
.get_names ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/monster_index/monster.rb', line 22 def self.get_names names = [] @@all.each do |monster| names << monster.name end names end |
.list ⇒ Object
30 31 32 33 34 35 |
# File 'lib/monster_index/monster.rb', line 30 def self.list @@all.each do |monster| puts "#{monster.name}" end puts end |
.list_some(letter) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/monster_index/monster.rb', line 37 def self.list_some(letter) @@all.each do |monster| if monster.name.downcase.match(/\A[#{letter.downcase}]/) puts "#{monster.name}" end end puts end |
.view_profile(name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/monster_index/monster.rb', line 46 def self.view_profile(name) monster = @@all.find {|one| one.name == name} puts "Size/Type: #{monster.size_type}" puts "Hit Dice: #{monster.hit_dice}" puts "Initiative: #{monster.initiative}" puts "Speed: #{monster.speed}" puts "AC: #{monster.ac}" puts "Attack: #{monster.attack}" puts "Alignment: #{monster.alignment}" puts "More info at: #{monster.url}" puts end |
Instance Method Details
#add_monster_attributes(attributes_hash) ⇒ Object
17 18 19 20 |
# File 'lib/monster_index/monster.rb', line 17 def add_monster_attributes(attributes_hash) attributes_hash.each {|key, value| self.send(("#{key}="), value)} self end |