1 | # Heros filtering and searching methods |
||
2 | |||
3 | View Code Duplication | def heros |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
4 | total_heros = Dir['./data/heroes/*'].length |
||
5 | [*0..(total_heros - 1)].map do |i| |
||
6 | h = load_yaml("/heroes/#{i}") |
||
7 | h['nivel'] = 1 unless h['nivel'] |
||
8 | h['ciudad'] = 'Jadessvärd' unless h['ciudad'] |
||
9 | h['id'] = i |
||
10 | Hero.new(h) |
||
11 | end |
||
12 | end |
||
13 | |||
14 | def filter_heros(criteria, palabra) |
||
15 | filtered_heros = |
||
16 | case criteria |
||
17 | when 'status' |
||
18 | # TODO: This should be API requests. |
||
19 | lista_status = |
||
20 | case palabra |
||
21 | when 'licenciados' then 'retirado' |
||
22 | when 'heroes' then 'activo' |
||
23 | when 'ausentes' then 'ausente' |
||
24 | when 'reservistas' then 'reserva' |
||
25 | when 'extranjeros' then 'extranjero' |
||
26 | end |
||
27 | |||
28 | heros.select { |h| h.estado.downcase.include?(lista_status) } |
||
29 | when 'heroe' |
||
30 | heros.select { |h| h.name.downcase.include?(palabra) } |
||
31 | when 'jugador' |
||
32 | heros.select { |h| h.jugador.downcase.include?(palabra) } |
||
33 | when 'raza' |
||
34 | heros.select { |h| h.raza.downcase.include?(palabra) } |
||
35 | when 'mascota' |
||
36 | con_mascota = heros.reject { |h| h.pet.nil? } |
||
37 | con_mascota.select { |h| h.pet.name.downcase.include?(palabra) } |
||
38 | end |
||
39 | |||
40 | filtered_heros.sort_by { |h| [h.nivel, h.reputacion] }.reverse |
||
41 | end |
||
42 | |||
43 | def hero(id) |
||
44 | heros[id] |
||
45 | end |
||
46 | |||
47 | def jugadores |
||
48 | (heros + renegados).map(&:jugador).uniq |
||
49 | end |
||
50 | |||
51 | def narrados(historiados) |
||
52 | narrados = heros.select { |p| p.historia if p.historia == historiados } |
||
53 | narrados.sort_by { |p| p.premio ? p.premio : 3 } |
||
54 | end |
||
55 | |||
56 | def nomalize_pj(personaje) |
||
57 | normalization = { |
||
58 | '%C3%A1' => 'á', |
||
59 | '%C3%A9' => 'é', |
||
60 | '%C3%AD' => 'í', |
||
61 | '%C3%B3' => 'ó', |
||
62 | '%C3%BA' => 'ú', |
||
63 | '%CF%B8' => 'ϸ', |
||
64 | } |
||
65 | personaje.gsub(/%C3%A1|%C3%A9|%C3%AD|%C3%B3|%C3%BA|%CF%B8/) do |match| |
||
66 | normalization[match] |
||
67 | end |
||
68 | end |
||
69 |