Class: MonsterIndex::Monster

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#acObject

Returns the value of attribute ac.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def ac
  @ac
end

#alignmentObject

Returns the value of attribute alignment.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def alignment
  @alignment
end

#attackObject

Returns the value of attribute attack.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def attack
  @attack
end

#hit_diceObject

Returns the value of attribute hit_dice.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def hit_dice
  @hit_dice
end

#initiativeObject

Returns the value of attribute initiative.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def initiative
  @initiative
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def name
  @name
end

#size_typeObject

Returns the value of attribute size_type.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def size_type
  @size_type
end

#speedObject

Returns the value of attribute speed.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def speed
  @speed
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/monster_index/monster.rb', line 2

def url
  @url
end

Class Method Details

.allObject



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_namesObject



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

.listObject



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