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