Class: Mondex::Monster

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Findable
Defined in:
lib/mondex/monster.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Findable

find_by_name

Constructor Details

#initialize(monster_hash) ⇒ Monster

Returns a new instance of Monster.



8
9
10
11
12
13
# File 'lib/mondex/monster.rb', line 8

def initialize(monster_hash)
  monster_hash.each do |attribute, value|
    self.send("#{attribute}=", value)
  end
  @@all << self
end

Instance Attribute Details

#bioObject

Returns the value of attribute bio.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def bio
  @bio
end

#elementsObject

Returns the value of attribute elements.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def elements
  @elements
end

#locationsObject

Returns the value of attribute locations.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def locations
  @locations
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def name
  @name
end

#resistancesObject

Returns the value of attribute resistances.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def resistances
  @resistances
end

#speciesObject (readonly)

Returns the value of attribute species.



4
5
6
# File 'lib/mondex/monster.rb', line 4

def species
  @species
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def url
  @url
end

#weaknessObject

Returns the value of attribute weakness.



3
4
5
# File 'lib/mondex/monster.rb', line 3

def weakness
  @weakness
end

Class Method Details

.allObject



15
16
17
# File 'lib/mondex/monster.rb', line 15

def self.all
  @@all
end

.create_from_list(monsters_array) ⇒ Object



19
20
21
22
23
# File 'lib/mondex/monster.rb', line 19

def self.create_from_list(monsters_array)
  monsters_array.each do |hash|
    Mondex::Monster.new(hash)
  end
end

Instance Method Details

#add_attributes(hash) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mondex/monster.rb', line 29

def add_attributes(hash)
  hash.each do |attribute, value|
    if attribute == :species
      new_species = Mondex::Species.create_or_find_by_name(value)
      self.add_species(new_species)
      new_species.add_monster(self)
    else
      self.send("#{attribute}=", value)
    end
  end
  self
end

#add_species(species) ⇒ Object



25
26
27
# File 'lib/mondex/monster.rb', line 25

def add_species(species)
  @species = species
end