Engarce.bonificador()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 23.225

Importance

Changes 0
Metric Value
cc 5
c 0
b 0
f 0
dl 0
loc 13
ccs 1
cts 10
cp 0.1
crap 23.225
rs 8.5454
1
# Engarce = objetos engarzables: gemas, joyas y runas
2 1
class Engarce < Hash
3 1
  attr_accessor :id, :name, :fits
4
5 1
  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 1
  def item
12
    self.class.to_s.downcase
13
  end
14
15 1
  def img_path
16
    "'../../images/treasures/#{item}s/#{name}.png'"
17
  end
18
19 1
  def big_img
20
    "'../../images/items/#{item}s/#{name}.png'"
21
  end
22
23 1
  def bonificador(item)
0 ignored issues
show
Coding Style introduced by
The Assignment, Branch, Condition size for bonificador is considered too high. [25.63/15]. The ABC size is based on assignments, branches (method calls), and conditions.
Loading history...
Coding Style introduced by
The method bonificador seems to be too complex. Perceived cyclomatic complexity is 10 with a maxiumum of 6 permitted.
Loading history...
Coding Style introduced by
This method is 11 lines long. Your coding style permits a maximum length of 10.
Loading history...
Complexity Coding Style introduced by
The method bonificador seems to be too complex. Perceived complexity is 11 with a maxiumum of 7 permitted.
Loading history...
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 1
  def disponibles
0 ignored issues
show
Coding Style introduced by
The Assignment, Branch, Condition size for disponibles is considered too high. [16.31/15]. The ABC size is based on assignments, branches (method calls), and conditions.
Loading history...
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