about summary refs log tree commit diff stats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/pokeviewer/pokemon.rb19
-rw-r--r--app/models/pokeviewer/trainer.rb27
2 files changed, 44 insertions, 2 deletions
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 3975550..d14ea87 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb
@@ -36,7 +36,7 @@ module Pokeviewer
36 enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, 36 enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k,
37 :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, 37 :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z,
38 :question, :exclamation] 38 :question, :exclamation]
39 39
40 validates :slot, presence: true, 40 validates :slot, presence: true,
41 uniqueness: { scope: [:trainer_id, :box] }, 41 uniqueness: { scope: [:trainer_id, :box] },
42 unless: Proc.new { |a| a.trainer.nil? } 42 unless: Proc.new { |a| a.trainer.nil? }
@@ -46,7 +46,22 @@ module Pokeviewer
46 end 46 end
47 47
48 def icon_path 48 def icon_path
49 "pokeviewer/icons/#{species_id}.png" 49 form = ""
50 if species_id == 201
51 # Handle Unown form
52 form = "-#{unown_letter}"
53 elsif species_id == 386
54 # Handle Deoxys forms
55 if trainer.firered?
56 form = "-attack"
57 elsif trainer.leafgreen?
58 form = "-defense"
59 elsif trainer.emerald?
60 form = "-speed"
61 end
62 end
63
64 "pokeviewer/icons/#{species_id}#{form}.png"
50 end 65 end
51 66
52 def sprite_path 67 def sprite_path
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index edfbd25..d3a5b91 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb
@@ -14,5 +14,32 @@ module Pokeviewer
14 validates :game, presence: true 14 validates :game, presence: true
15 enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald], 15 enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald],
16 predicates: true 16 predicates: true
17
18 def display_number
19 number.to_s.rjust(5, '0')
20 end
21
22 def party
23 pokemon.where(box: nil).order("slot ASC")
24 end
25
26 def boxes
27 (0..13).map { |i| box(i) }
28 end
29
30 def box(number)
31 pokes = pokemon.where(box: number).order("slot ASC").to_a
32
33 result = []
34 (0..29).each do |i|
35 if pokes.empty? or (pokes.first.slot == i)
36 result << pokes.shift
37 else
38 result << nil
39 end
40 end
41
42 result
43 end
17 end 44 end
18end 45end