calcular_coste()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
# Calcula el coste de un objeto
2
def calcular_coste(p) # p = objeto a calcular
0 ignored issues
show
Coding Style introduced by
The Assignment, Branch, Condition size for calcular_coste is considered too high. [16.58/15]. The ABC size is based on assignments, branches (method calls), and conditions.
Loading history...
3
  # Inicializamos
4
  coste = 0
5
  eng = p[:engarces].split(',').sort.reverse
6
  eng.each_with_index do |e, i|
7
    # Coste de los engarces (joyas y runas = 4)
8
    valor_calibre = [5, 10, 25, 50, 100, 250, 500]
9
    # Avoid negative index values
10
    coste += valor_calibre[e.to_i - i] if (e.to_i - i) >= 0
11
  end
12
  # Reputacion
13
  coste *= 0.9**p[:repu].to_i # Factor de Repu
14
  coste.round # Redondea el coste sin decimales
15
end
16