diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/pokeviewer/pokedex_helper.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/app/helpers/pokeviewer/pokedex_helper.rb b/app/helpers/pokeviewer/pokedex_helper.rb new file mode 100644 index 0000000..fe3e575 --- /dev/null +++ b/app/helpers/pokeviewer/pokedex_helper.rb | |||
@@ -0,0 +1,51 @@ | |||
1 | module Pokeviewer | ||
2 | module PokedexHelper | ||
3 | |||
4 | def pokedex_table(all_species, trainers) | ||
5 | final_result = "".html_safe | ||
6 | |||
7 | all_species.each do |species| | ||
8 | noted_trainers = species.pokedex_entries.to_a | ||
9 | |||
10 | if noted_trainers.empty? | ||
11 | poke_name = "???" | ||
12 | poke_image = image_tag "pokeviewer/icons/0.png" | ||
13 | else | ||
14 | poke_name = species.name | ||
15 | poke_image = image_tag "pokeviewer/icons/#{species.id}.png" | ||
16 | end | ||
17 | |||
18 | result = "".html_safe | ||
19 | |||
20 | result << tag.th("\##{species.id}") | ||
21 | result << tag.th(poke_name) | ||
22 | result << tag.th(poke_image) | ||
23 | |||
24 | trainers.each do |trainer| | ||
25 | if !noted_trainers.empty? and noted_trainers.first.trainer_id == trainer.id | ||
26 | nt = noted_trainers.shift | ||
27 | |||
28 | if nt.caught | ||
29 | result << tag.td(trainer.display_number, | ||
30 | class: ["pkvd-caught", trainer.game]) | ||
31 | else | ||
32 | result << tag.td(trainer.display_number, | ||
33 | class: ["pkvd-seen", trainer.game]) | ||
34 | end | ||
35 | else | ||
36 | result << tag.td(trainer.display_number, class: "pkvd-unseen") | ||
37 | end | ||
38 | end | ||
39 | |||
40 | result << tag.td( | ||
41 | species.current_revisions.map { | ||
42 | |p| link_to p.nickname, p.pokemon }.join(", ").html_safe) | ||
43 | |||
44 | final_result << tag.tr(result) | ||
45 | end | ||
46 | |||
47 | tag.table(final_result, class: "pkvd-table") | ||
48 | end | ||
49 | |||
50 | end | ||
51 | end | ||