Engarce.bonificador()   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 13
rs 9.2833
c 0
b 0
f 0
1
# Engarce = objetos engarzables: gemas, joyas y runas
2
class Engarce < Hash
3
  attr_accessor :id, :name, :fits, :color
4
5
  def initialize(args)
6
    args.each do |k, v|
7
      instance_variable_set("@#{k}".to_sym, v) unless v.nil?
8
    end
9
  end
10
11
  def item
12
    self.class.to_s.downcase
13
  end
14
15
  def img_path
16
    "/images/treasures/#{item}s/#{name}.png"
17
  end
18
19
  def big_img
20
    "/images/items/#{item}s/#{name}.png"
21
  end
22
23
  def bonificador(item)
24
    if item.fits == 'arma'
25
      fits[item.categoria] || fits['arma'] || 'Armas sin implementar'
26
    elsif item.fits == 'armadura'
27
      fits[item.categoria] || fits['pecho'] || 'Armaduras sin implementar'
28
    elsif fits[item.fits]
29
      fits[item.fits]
30
    elsif item.class == Proteccion
31
      fits['armadura'] || 'Sin bonificador'
32
    else
33
      'Sin efecto'
34
    end
35
  end
36
37
  # returns from heros.tesoro, the list of (maybe repeated)
38
  # ids of the heros with self.id gem/runa/joya available
39
  def disponibles
40
    total = []
41
    heros.each do |h|
42
      next unless h.tesoro
43
      next unless h.tesoro[item + 's']
44
      h.tesoro[item + 's'].each do |e|
45
        (total << h.id) if e == id
46
      end
47
    end
48
    total
49
  end
50
end
51