pokedex-terminal 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/classes/Print.rb CHANGED
@@ -1,16 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './Main_menu'
2
4
  require 'colorize'
3
5
 
4
6
  class Print
5
-
6
7
  def self.print_pokemon_expanded(hash)
7
- system 'clear'
8
- puts "-" * 40
9
- puts "#{hash[:name]}"
10
- puts "-" * 40
11
- print "#{hash[:name]} belongs to the #{hash[:type_1]} type"
12
- if hash[:type_2] != nil
13
- print ", with a secondary type of #{hash[:type_2]} \n"
8
+ puts '-' * 40
9
+ puts (hash[:name]).to_s
10
+ puts '-' * 40
11
+ print "#{hash[:name]} belongs to the #{colorize_attribute(hash, :type_1, :type_1)} type"
12
+ if !hash[:type_2].nil?
13
+ print ", with a secondary type of #{colorize_attribute(hash, :type_2, :type_2)} \n"
14
14
  else
15
15
  print ".\n"
16
16
  end
@@ -23,42 +23,56 @@ class Print
23
23
  if hash[:legendary] == 'True'
24
24
  puts "Most importantly, #{hash[:name]} is a legendary Pokemon!"
25
25
  end
26
- puts "-" * 40
26
+ puts '-' * 40
27
27
  Main_menu.return?
28
28
  end
29
29
 
30
30
  def self.print_pokemon_condensed(hash)
31
- system 'clear'
32
- name = "#{hash[:name]}"
33
- case hash[:type_1]
34
- when "Normal"
35
- puts name
36
- when "Fire"
37
- puts name.colorize(:red)
38
- when "Water"
39
- puts name.colorize(:blue)
40
- when "Grass"
41
- puts name.colorize(:green)
42
- when "Electric"
43
- puts name.colorize(:light_blue)
44
- when "Ice"
45
- puts name.colorize(:grey)
46
- when "Fighting"
47
- puts name.colorize(:yellow)
48
- when "Poison"
49
- puts name.colorize(:purple)
50
- when "Ground"
51
- puts name.colorize(:brown)
52
- when "Flying"
53
- when "Psychic"
54
- when "Bug"
55
- when "Rock"
56
- when "Ghost"
57
- when "Dark"
58
- when "Dragon"
59
- when "Steel"
60
- when "Fairy"
61
- end
31
+ puts colorize_attribute(hash, :name, :type_1)
62
32
  end
63
33
 
64
- end
34
+ def self.colorize_attribute(hash, key, type)
35
+ attribute = ''
36
+ hash.each do |k, v|
37
+ attribute = v if k == key
38
+ end
39
+ case hash[type]
40
+ when 'Normal'
41
+ attribute
42
+ when 'Fire'
43
+ attribute.colorize(:red)
44
+ when 'Water'
45
+ attribute.colorize(:blue)
46
+ when 'Grass'
47
+ attribute.colorize(:green)
48
+ when 'Electric'
49
+ attribute.colorize(:light_blue)
50
+ when 'Ice'
51
+ attribute.colorize(:default)
52
+ when 'Fighting'
53
+ attribute.colorize(:light_red)
54
+ when 'Poison'
55
+ attribute.colorize(:cyan)
56
+ when 'Ground'
57
+ attribute.colorize(:default)
58
+ when 'Flying'
59
+ attribute.colorize(:light_white)
60
+ when 'Psychic'
61
+ attribute.colorize(:light_magenta)
62
+ when 'Bug'
63
+ attribute.colorize(:light_green)
64
+ when 'Rock'
65
+ attribute.colorize(:white)
66
+ when 'Ghost'
67
+ attribute.colorize(:light_black)
68
+ when 'Dark'
69
+ attribute.colorize(:black)
70
+ when 'Dragon'
71
+ attribute.colorize(:light_yellow)
72
+ when 'Steel'
73
+ attribute.colorize(:light_cyan)
74
+ when 'Fairy'
75
+ attribute.colorize(:magenta)
76
+ end
77
+ end
78
+ end
@@ -1,27 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './Print'
2
4
  require_relative './Main_menu'
3
5
 
4
6
  class Search
5
-
6
7
  def self.by_name(data)
7
8
  search_prompt = TTY::Prompt.new(active_color: :red)
8
9
  poke_array = []
9
10
  data.each do |hash|
10
- hash.each do |k,v|
11
- if k == :name
12
- poke_array << v
13
- end
11
+ hash.each do |k, v|
12
+ poke_array << v if k == :name
14
13
  end
15
14
  end
16
- return search_prompt.select('Please enter the name of the Pokemon you\'re looking for.', poke_array, filter: true)
15
+ search_prompt.select('Please enter the name of the Pokemon you\'re looking for.', poke_array, filter: true)
17
16
  end
18
17
 
19
18
  def self.return_hash(data, name)
20
19
  data.each do |hash|
21
- if hash[:name] == name
22
- return hash
23
- end
20
+ return hash if hash[:name] == name
24
21
  end
25
22
  end
26
-
27
- end
23
+ end
@@ -1,69 +1,71 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './New'
2
4
  require_relative './Search'
3
5
 
4
6
  class Update
5
-
6
7
  def self.update_pokemon_menu(data)
7
8
  update_prompt = TTY::Prompt.new(active_color: :red)
8
9
  name = Search.by_name(data)
9
10
  data.each do |hash|
10
- if hash[:name] == name
11
- user_input = update_prompt.select("Which attribute would you like to update?") do |menu|
12
- menu.choice "Name", 1
13
- menu.choice "Type", 2
14
- menu.choice "Secondary Type", 3
15
- menu.choice "HP", 4
16
- menu.choice "Attack", 5
17
- menu.choice "Defense", 6
18
- menu.choice "Special Attack", 7
19
- menu.choice "Special Defense", 8
20
- menu.choice "Speed", 9
21
- menu.choice "Generation", 10
22
- menu.choice "Legendary", 11
23
- menu.choice "Exit this menu", 12
24
- end
25
- case user_input
26
- when 1
27
- puts "What would you like #{hash[:name]}'s new name to be?"
28
- name = New.add_name
29
- hash[:name] = name
30
- when 2
31
- puts "What would you like #{hash[:name]}'s new type to be?"
32
- type_1 = New.add_type
33
- hash[:type_1] = type_1
34
- when 3
35
- puts "What would you like #{hash[:name]}'s new secondary type to be?"
36
- type_2 = New.add_type
37
- hash[:type_2] = type_2
38
- when 4
39
- hp = New.add_points('HP')
40
- hash[:hp] = hp
41
- when 5
42
- attack = New.add_points('Attack')
43
- hash[:attack] = attack
44
- when 6
45
- defense = New.add_points('Defense')
46
- hash[:defense] = defense
47
- when 7
48
- sp_atk = New.add_points('Special Attack')
49
- hash[:"sp._atk"] = sp_atk
50
- when 8
51
- sp_def = New.add_points('Special Defense')
52
- hash[:"sp._def"] = sp_def
53
- when 9
54
- speed = New.add_points('Speed')
55
- hash[:speed] = speed
56
- when 10
57
- generation = New.add_generation
58
- hash[:generation] = generation
59
- when 11
60
- legendary = New.add_legendary
61
- hash[:legendary] = legendary
62
- when 12
63
- Main_menu.run
64
- end
11
+ next unless hash[:name] == name
12
+
13
+ user_input = update_prompt.select('Which attribute would you like to update?') do |menu|
14
+ menu.choice 'Name', 1
15
+ menu.choice 'Type', 2
16
+ menu.choice 'Secondary Type', 3
17
+ menu.choice 'HP', 4
18
+ menu.choice 'Attack', 5
19
+ menu.choice 'Defense', 6
20
+ menu.choice 'Special Attack', 7
21
+ menu.choice 'Special Defense', 8
22
+ menu.choice 'Speed', 9
23
+ menu.choice 'Generation', 10
24
+ menu.choice 'Legendary', 11
25
+ menu.choice 'Exit this menu', 12
65
26
  end
27
+ case user_input
28
+ when 1
29
+ puts "What would you like #{hash[:name]}'s new name to be?"
30
+ name = New.add_name
31
+ hash[:name] = name
32
+ when 2
33
+ puts "What would you like #{hash[:name]}'s new type to be?"
34
+ type_1 = New.add_type
35
+ hash[:type_1] = type_1
36
+ when 3
37
+ puts "What would you like #{hash[:name]}'s new secondary type to be?"
38
+ type_2 = New.add_type
39
+ hash[:type_2] = type_2
40
+ when 4
41
+ hp = New.add_points('HP')
42
+ hash[:hp] = hp
43
+ when 5
44
+ attack = New.add_points('Attack')
45
+ hash[:attack] = attack
46
+ when 6
47
+ defense = New.add_points('Defense')
48
+ hash[:defense] = defense
49
+ when 7
50
+ sp_atk = New.add_points('Special Attack')
51
+ hash[:"sp._atk"] = sp_atk
52
+ when 8
53
+ sp_def = New.add_points('Special Defense')
54
+ hash[:"sp._def"] = sp_def
55
+ when 9
56
+ speed = New.add_points('Speed')
57
+ hash[:speed] = speed
58
+ when 10
59
+ generation = New.add_generation
60
+ hash[:generation] = generation
61
+ when 11
62
+ legendary = New.add_legendary
63
+ hash[:legendary] = legendary
64
+ when 12
65
+ Main_menu.run
66
+ end
67
+ hash[:total] = hash[:hp] + hash[:attack] + hash[:defense] + hash[:"sp._atk"] + hash[:"sp._def"] + hash[:speed]
68
+ Print.print_pokemon_expanded(hash)
66
69
  end
67
70
  end
68
-
69
71
  end