pokedex-terminal 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +213 -21
- data/README.md +50 -13
- data/bin/pokedex-terminal +5 -0
- data/data/pokemon.csv +802 -0
- data/lib/pokedex/classes/Delete.rb +30 -0
- data/lib/pokedex/classes/List.rb +73 -0
- data/lib/pokedex/classes/Main_menu.rb +67 -0
- data/lib/pokedex/classes/New.rb +98 -0
- data/lib/pokedex/classes/Pokemon.rb +16 -0
- data/lib/pokedex/classes/Print.rb +62 -0
- data/lib/pokedex/classes/Search.rb +27 -0
- data/lib/pokedex/classes/Update.rb +69 -0
- data/lib/pokedex/terminal.rb +5 -7
- data/lib/pokedex/terminal.rb.save +8 -0
- data/lib/pokedex/terminal/version.rb +1 -1
- data/lib/pokedex/test.rb +6 -0
- data/lib/pokedex/titlesequence.plaintext +13 -0
- data/pokedex-terminal.gemspec +5 -2
- metadata +72 -4
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'tty-prompt'
|
2
|
+
require_relative './Main_menu'
|
3
|
+
|
4
|
+
class Delete
|
5
|
+
|
6
|
+
def self.delete(data)
|
7
|
+
delete_prompt = TTY::Prompt.new(active_color: :red)
|
8
|
+
poke_array = []
|
9
|
+
data.each do |hash|
|
10
|
+
hash.each do |k,v|
|
11
|
+
if k == :name
|
12
|
+
poke_array << v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
user_input = delete_prompt.select('Please enter the name of the Pokemon you\'re looking to delete', poke_array, filter: true)
|
17
|
+
data.each_with_index do |hash, index|
|
18
|
+
if hash[:name] == user_input
|
19
|
+
user_input_2 = delete_prompt.yes?("Are you sure you want to permanently delete #{hash[:name]}?")
|
20
|
+
if user_input_2 == true
|
21
|
+
data.delete_at(index)
|
22
|
+
return data
|
23
|
+
else
|
24
|
+
Main_menu.run
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'tty-prompt'
|
2
|
+
|
3
|
+
class List
|
4
|
+
|
5
|
+
def self.list_menu(data)
|
6
|
+
while true
|
7
|
+
list_prompt = TTY::Prompt.new(active_color: :red)
|
8
|
+
user_input = list_prompt.select("How would you like to list the Pokemon?\nPlease enter one of the following options.") do |menu|
|
9
|
+
menu.choice "List all", 1
|
10
|
+
menu.choice "List by Type", 2
|
11
|
+
menu.choice "List by Secondary Type",3
|
12
|
+
menu.choice "List by Generation", 4
|
13
|
+
menu.choice "List Legendary Pokemon", 5
|
14
|
+
end
|
15
|
+
case user_input
|
16
|
+
when 1
|
17
|
+
puts "-" * 40
|
18
|
+
puts "Listing all Pokemon"
|
19
|
+
puts "-" * 40
|
20
|
+
list_all(data)
|
21
|
+
when 2
|
22
|
+
puts "Which Type would you like to list by?"
|
23
|
+
user_input = New.add_type
|
24
|
+
puts "-" * 40
|
25
|
+
puts "Listing by #{user_input} Type:"
|
26
|
+
puts "-" * 40
|
27
|
+
list_by(data,:type_1,user_input)
|
28
|
+
when 3
|
29
|
+
puts "Which Secondary Type would you like to list by?"
|
30
|
+
user_input = New.add_type
|
31
|
+
puts "-" * 40
|
32
|
+
puts "Listing by #{user_input} Secondary Type:"
|
33
|
+
puts "-" * 40
|
34
|
+
list_by(data,:type_2,user_input)
|
35
|
+
when 4
|
36
|
+
while true
|
37
|
+
user_input = list_prompt.ask("Which generation would you like to list by?\nInput a number between 1-8.") { |q| q.in('1-8') }
|
38
|
+
puts "-" * 40
|
39
|
+
puts "Listing by Generation #{user_input}"
|
40
|
+
puts "-" * 40
|
41
|
+
list_by(data,:generation, user_input.to_i)
|
42
|
+
end
|
43
|
+
when 5
|
44
|
+
puts "-" * 40
|
45
|
+
puts "Listing Legendary Pokemon"
|
46
|
+
puts "-" * 40
|
47
|
+
list_by(data,:legendary,'True')
|
48
|
+
else
|
49
|
+
puts "Invalid selection, please enter a number between 1-5."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.list_all(data)
|
55
|
+
data.each do |hash|
|
56
|
+
Print.print_pokemon_condensed(hash)
|
57
|
+
end
|
58
|
+
puts "-" * 40
|
59
|
+
Main_menu.return?
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.list_by(data,attribute,value)
|
63
|
+
data.each do |hash|
|
64
|
+
if hash[attribute] == value
|
65
|
+
Print.print_pokemon_condensed(hash)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
puts "-" * 40
|
69
|
+
Main_menu.return?
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative './Search'
|
2
|
+
require_relative './Update'
|
3
|
+
require_relative './New'
|
4
|
+
require_relative './List'
|
5
|
+
require_relative './Delete'
|
6
|
+
require 'tty-prompt'
|
7
|
+
require 'smarter_csv'
|
8
|
+
|
9
|
+
class Main_menu
|
10
|
+
@@pokemon_data = SmarterCSV.process('../../data/pokemon.csv')
|
11
|
+
|
12
|
+
def self.run
|
13
|
+
while true
|
14
|
+
main_menu_prompt = TTY::Prompt.new(active_color: :red)
|
15
|
+
puts "-" * 40
|
16
|
+
# main_menu_prompt.warn(" Welcome to your Pokedex!")
|
17
|
+
puts " Welcome to your Pokedex! ".blue.on_red.blink
|
18
|
+
puts "-" * 40
|
19
|
+
user_input = main_menu_prompt.select("Please select from the following:") do |menu|
|
20
|
+
menu.choice 'List Pokemon', 1
|
21
|
+
menu.choice 'Search for a Pokemon', 2
|
22
|
+
menu.choice 'Update an existing Pokemon', 3
|
23
|
+
menu.choice 'Add a new Pokemon', 4
|
24
|
+
menu.choice 'Delete a Pokemon', 5
|
25
|
+
menu.choice 'Exit', 6
|
26
|
+
menu.choice 'Print hashes', 7
|
27
|
+
end
|
28
|
+
case user_input
|
29
|
+
when 1
|
30
|
+
List.list_menu(@@pokemon_data)
|
31
|
+
when 2
|
32
|
+
name = Search.by_name(@@pokemon_data)
|
33
|
+
hash = Search.return_hash(@@pokemon_data, name)
|
34
|
+
Print.print_pokemon_expanded(hash)
|
35
|
+
when 3
|
36
|
+
Update.update_pokemon_menu(@@pokemon_data)
|
37
|
+
## Incomplete
|
38
|
+
when 4
|
39
|
+
new_hash = New.add_pokemon
|
40
|
+
@@pokemon_data << new_hash
|
41
|
+
Print.print_pokemon_expanded(new_hash)
|
42
|
+
when 5
|
43
|
+
@@pokemon_data = Delete.delete(@@pokemon_data)
|
44
|
+
when 6
|
45
|
+
CSV.open('../../data/pokemon.csv', "wb") do |csv|
|
46
|
+
keys = @@pokemon_data.first.keys
|
47
|
+
csv << keys
|
48
|
+
@@pokemon_data.each do |hash|
|
49
|
+
csv << hash.values_at(*keys)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
exit
|
53
|
+
when 7
|
54
|
+
pp @@pokemon_data
|
55
|
+
else
|
56
|
+
"Invalid selection, please select from the following options."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.return?
|
62
|
+
puts "Press enter to return to the Main Menu."
|
63
|
+
user_input = gets.chomp
|
64
|
+
run()
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class New
|
2
|
+
|
3
|
+
def self.add_pokemon
|
4
|
+
puts "So you want to create a new Pokemon, what will you call it?"
|
5
|
+
name = add_name()
|
6
|
+
puts "What type will your Pokemon belong to?"
|
7
|
+
type_1 = add_type()
|
8
|
+
puts "Now for the secondary type."
|
9
|
+
type_2 = add_type()
|
10
|
+
hp = add_points('HP')
|
11
|
+
attack = add_points('Attack')
|
12
|
+
defense = add_points('Defense')
|
13
|
+
sp_atk = add_points('Special Attack')
|
14
|
+
sp_def = add_points('Special Defense')
|
15
|
+
speed = add_points('Speed')
|
16
|
+
generation = add_generation()
|
17
|
+
legendary = add_legendary()
|
18
|
+
total = hp + attack + sp_atk + sp_def + speed
|
19
|
+
hash = {}
|
20
|
+
hash[:name] = name
|
21
|
+
hash[:type_1] = type_1
|
22
|
+
hash[:type_2] = type_2
|
23
|
+
hash[:total] = total
|
24
|
+
hash[:hp] = hp
|
25
|
+
hash[:attack] = attack
|
26
|
+
hash[:defense] = defense
|
27
|
+
hash[:"sp._atk"] = sp_atk
|
28
|
+
hash[:"sp._def"] = sp_def
|
29
|
+
hash[:speed] = speed
|
30
|
+
hash[:generation] = generation
|
31
|
+
hash[:legendary] = legendary
|
32
|
+
pp hash
|
33
|
+
return hash
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def self.add_name
|
38
|
+
print "> "
|
39
|
+
return gets.chomp
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.add_type
|
43
|
+
new_prompt = TTY::Prompt.new(active_color: :red)
|
44
|
+
user_input = new_prompt.select("Please select a Type.") do |menu|
|
45
|
+
menu.choice "Normal"
|
46
|
+
menu.choice "Fire"
|
47
|
+
menu.choice "Water"
|
48
|
+
menu.choice "Grass"
|
49
|
+
menu.choice "Electric"
|
50
|
+
menu.choice "Ice"
|
51
|
+
menu.choice "Fighting"
|
52
|
+
menu.choice "Poison"
|
53
|
+
menu.choice "Ground"
|
54
|
+
menu.choice "Flying"
|
55
|
+
menu.choice "Psychic"
|
56
|
+
menu.choice "Bug"
|
57
|
+
menu.choice "Rock"
|
58
|
+
menu.choice "Ghost"
|
59
|
+
menu.choice "Dark"
|
60
|
+
menu.choice "Dragon"
|
61
|
+
menu.choice "Steel"
|
62
|
+
menu.choice "Fairy"
|
63
|
+
end
|
64
|
+
return user_input
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.add_points(attribute)
|
68
|
+
while true
|
69
|
+
puts "How many points would you like this Pokemon to have for #{attribute}?"
|
70
|
+
print "> "
|
71
|
+
user_input = gets.chomp.to_i
|
72
|
+
if user_input > 0
|
73
|
+
return user_input
|
74
|
+
else
|
75
|
+
puts "Invalid selection. Please input a number greater than 0."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.add_generation
|
81
|
+
new_prompt = TTY::Prompt.new(active_color: :red)
|
82
|
+
user_input = new_prompt.ask("Which generation does this Pokemon belong to?\nInput a number between 1-8.") do |q|
|
83
|
+
q.in('1-8')
|
84
|
+
q.messages[:valid?] = 'Invalid number, select a number from 1-8'
|
85
|
+
end
|
86
|
+
return user_input
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.add_legendary
|
90
|
+
new_prompt = TTY::Prompt.new(active_color: :red)
|
91
|
+
user_input = new_prompt.yes?('Is this Pokemon legendary?') do |q|
|
92
|
+
q.messages[:valid?] = "Invalid response, select 'Y' or 'n'"
|
93
|
+
end
|
94
|
+
p user_input
|
95
|
+
return user_input = true ? 'True' : 'False'
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Pokemon
|
2
|
+
def initialize(hash)
|
3
|
+
@name = hash[:name]
|
4
|
+
@type_1 = hash[:type_1]
|
5
|
+
@type_2 = hash[:type_2]
|
6
|
+
@total = hash[:total]
|
7
|
+
@hp = hash[:hp]
|
8
|
+
@attack = hash[:attack]
|
9
|
+
@defense = hash[:defense]
|
10
|
+
@sp_atk = hash[:"sp._atk"]
|
11
|
+
@sp_def = hash[:"sp._def"]
|
12
|
+
@speed = hash[:speed]
|
13
|
+
@generation = hash[:generation]
|
14
|
+
@legendary = hash[:legendary]
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative './Main_menu'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
class Print
|
5
|
+
|
6
|
+
def self.print_pokemon_expanded(hash)
|
7
|
+
puts "-" * 40
|
8
|
+
puts "#{hash[:name]}"
|
9
|
+
puts "-" * 40
|
10
|
+
print "#{hash[:name]} belongs to the #{hash[:type_1]} type"
|
11
|
+
if hash[:type_2] != nil
|
12
|
+
print ", with a secondary type of #{hash[:type_2]} \n"
|
13
|
+
else
|
14
|
+
print ".\n"
|
15
|
+
end
|
16
|
+
puts "Total: #{hash[:total]}"
|
17
|
+
puts "HP: #{hash[:hp]}"
|
18
|
+
print "Attack: #{hash[:attack]} Defense :#{hash[:defense]}\n"
|
19
|
+
print "Special Attack: #{hash[:"sp._atk"]} Special Defense: #{hash[:"sp._def"]}\n"
|
20
|
+
puts "Speed: #{hash[:speed]}"
|
21
|
+
puts "They are of Generation #{hash[:generation]}."
|
22
|
+
if hash[:legendary] == 'True'
|
23
|
+
puts "Most importantly, #{hash[:name]} is a legendary Pokemon!"
|
24
|
+
end
|
25
|
+
puts "-" * 40
|
26
|
+
Main_menu.return?
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.print_pokemon_condensed(hash)
|
30
|
+
name = "#{hash[:name]}"
|
31
|
+
case hash[:type_1]
|
32
|
+
when "Normal"
|
33
|
+
puts name
|
34
|
+
when "Fire"
|
35
|
+
puts name.colorize(:red)
|
36
|
+
when "Water"
|
37
|
+
puts name.colorize(:blue)
|
38
|
+
when "Grass"
|
39
|
+
puts name.colorize(:green)
|
40
|
+
when "Electric"
|
41
|
+
puts name.colorize(:light_blue)
|
42
|
+
when "Ice"
|
43
|
+
puts name.colorize(:grey)
|
44
|
+
when "Fighting"
|
45
|
+
puts name.colorize(:yellow)
|
46
|
+
when "Poison"
|
47
|
+
puts name.colorize(:purple)
|
48
|
+
when "Ground"
|
49
|
+
puts name.colorize(:brown)
|
50
|
+
when "Flying"
|
51
|
+
when "Psychic"
|
52
|
+
when "Bug"
|
53
|
+
when "Rock"
|
54
|
+
when "Ghost"
|
55
|
+
when "Dark"
|
56
|
+
when "Dragon"
|
57
|
+
when "Steel"
|
58
|
+
when "Fairy"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative './Print'
|
2
|
+
require_relative './Main_menu'
|
3
|
+
|
4
|
+
class Search
|
5
|
+
|
6
|
+
def self.by_name(data)
|
7
|
+
search_prompt = TTY::Prompt.new(active_color: :red)
|
8
|
+
poke_array = []
|
9
|
+
data.each do |hash|
|
10
|
+
hash.each do |k,v|
|
11
|
+
if k == :name
|
12
|
+
poke_array << v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return search_prompt.select('Please enter the name of the Pokemon you\'re looking for.', poke_array, filter: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.return_hash(data, name)
|
20
|
+
data.each do |hash|
|
21
|
+
if hash[:name] == name
|
22
|
+
return hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative './New'
|
2
|
+
require_relative './Search'
|
3
|
+
|
4
|
+
class Update
|
5
|
+
|
6
|
+
def self.update_pokemon_menu(data)
|
7
|
+
update_prompt = TTY::Prompt.new(active_color: :red)
|
8
|
+
name = Search.by_name(data)
|
9
|
+
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
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|