dexter_plusplus 0.2.0

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.
@@ -0,0 +1,75 @@
1
+ class Item
2
+ extend Findable
3
+
4
+ attr_accessor :name, :url, :effect, :id, :data
5
+ @@all = []
6
+ @@tag = "item"
7
+ @@limit = 954
8
+
9
+ def initialize(name, url)
10
+ self.name = name
11
+ self.url = url
12
+ self.data = JSON.parse(RestClient.get(url))
13
+ self.set_attributes
14
+ @@all << self
15
+ end
16
+
17
+ def self.all
18
+ @@all
19
+ end
20
+
21
+ def self.tag
22
+ @@tag
23
+ end
24
+
25
+ def self.limit
26
+ @@limit
27
+ end
28
+
29
+ def tag
30
+ @@tag
31
+ end
32
+
33
+ def set_attributes
34
+ self.set_effect
35
+ self.set_id
36
+ end
37
+
38
+ def set_effect
39
+ self.effect = self.data["effect_entries"][0]["effect"]
40
+ end
41
+
42
+ def set_id
43
+ self.id = self.data["id"]
44
+ end
45
+
46
+ def print_name
47
+ puts "Name: #{self.name.capitalize.light_green}"
48
+ end
49
+ def get_colored_name
50
+ self.name.capitalize.light_green
51
+ end
52
+
53
+ def print_effect
54
+ puts "Effect: #{self.effect}"
55
+ end
56
+
57
+ def print_all
58
+ puts "---------------------------------------------------------"
59
+ puts " Dexter++ : Item ".light_green
60
+ puts "---------------------------------------------------------"
61
+ self.print_name
62
+ puts ""
63
+ self.print_effect
64
+ puts "---------------------------------------------------------"
65
+ end
66
+
67
+ def self.print_all
68
+ self.all.each{|item| item.print_all}
69
+ end
70
+
71
+
72
+
73
+
74
+
75
+ end
@@ -0,0 +1,83 @@
1
+ class ItemMenu
2
+ attr_accessor :cli
3
+
4
+ def initialize(cli)
5
+ self.cli = cli
6
+ end
7
+
8
+ def main_menu
9
+ puts "\n\n"
10
+ input = cli.prompt.select("What Item information would you like to get?", cycle: true) do |menu|
11
+ menu.choice 'Get a list of Items', 1
12
+ menu.choice 'Search for an Item by name', 2
13
+ menu.choice 'Get information from a random Item', 3
14
+ menu.choice 'Return to main menu'.light_green, 4
15
+ menu.choice 'Exit Dexter++'.light_red, 5
16
+ end
17
+ case input
18
+ when 1
19
+ self.list_items
20
+ when 2
21
+ self.search_by_name
22
+ when 3
23
+ self.get_random
24
+ when 4
25
+ self.cli.main_menu
26
+ when 5
27
+ self.cli.exit_program
28
+ end
29
+ end
30
+
31
+ def list_items
32
+ puts "\n\nHow many items would you like to list?"
33
+ input = gets.strip.to_i
34
+ until input.between?(1, Item.limit)
35
+ if input <= 0
36
+ puts"\nThat is not enough Items! Try a bigger number"
37
+ input = gets.strip.to_i
38
+ else
39
+ puts "\nThats way too many Items! Try a smaller number."
40
+ input = gets.strip.to_i
41
+ end
42
+ end
43
+ puts "\n\nAwesome! Let me load that for you."
44
+ puts"\n\n"
45
+ options = Item.find_with_offset_and_limit(rand(0...Item.limit), input)
46
+ self.display_item_options(options)
47
+ end
48
+
49
+ def get_random
50
+ item = API.get_random_item
51
+ item.print_all
52
+ puts"\n\n"
53
+ self.main_menu
54
+ end
55
+
56
+ def search_by_name
57
+ puts "\n\nWhat Item would you like to search for?"
58
+ input = gets.strip.downcase
59
+ puts "\n\nAwesome! Let me load that for you."
60
+ item = API.get_item_by_name(input)
61
+ item.print_all
62
+ puts"\n\n"
63
+ self.main_menu
64
+ end
65
+
66
+ def display_item_options(options)
67
+ options.unshift("Exit Dexter++".light_red)
68
+ options.unshift("Go back to main menu".light_green)
69
+ choice = self.cli.get_menu_from_array(options)
70
+ if choice == "Exit Dexter++".light_red
71
+ self.exit
72
+ elsif choice == "Go back to main menu".light_green
73
+ self.main_menu
74
+ else item = API.get_item_by_name(choice.downcase)
75
+ puts "\n\n\n"
76
+ item.print_all
77
+ end
78
+ puts "\n\n"
79
+ self.main_menu
80
+ end
81
+
82
+
83
+ end
@@ -0,0 +1,113 @@
1
+ class Move
2
+ extend Findable
3
+
4
+
5
+ attr_accessor :url, :data, :name, :accuracy, :effect, :power, :pp, :type, :pokemon_with_move, :id
6
+ @@all =[]
7
+ @@tag = "move"
8
+ @@limit = 746
9
+
10
+ def initialize(name, url)
11
+ self.name = name
12
+ self.url = url
13
+ self.data = JSON.parse(RestClient.get(url))
14
+ self.set_attributes
15
+ self.pokemon_with_move = []
16
+ @@all << self
17
+ end
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ def self.tag
24
+ @@tag
25
+ end
26
+
27
+ def self.limit
28
+ @@limit
29
+ end
30
+
31
+ def set_attributes
32
+ self.set_accuracy
33
+ self.set_type
34
+ self.set_effect
35
+ self.set_power
36
+ self.set_pp
37
+ self.set_id
38
+ end
39
+
40
+ def set_type
41
+ self.type = Type.find_or_create_by_name(self.data["type"]["name"])
42
+ end
43
+
44
+ def set_accuracy
45
+ self.accuracy = self.data["accuracy"]
46
+ end
47
+
48
+ def set_effect
49
+ self.effect = self.data["effect_entries"][0]["effect"]
50
+ end
51
+
52
+ def set_power
53
+ self.power = self.data["power"]
54
+ end
55
+
56
+ def set_pp
57
+ self.pp = self.data["pp"]
58
+ end
59
+
60
+ def set_id
61
+ self.id = self.data["id"]
62
+ end
63
+
64
+ def add_pokemon(pokemon)
65
+ self.pokemon_with_move << pokemon
66
+ end
67
+
68
+ def print_all
69
+ puts "---------------------------------------------------------"
70
+ puts " Dexter++ : Move ".light_red
71
+ puts "---------------------------------------------------------"
72
+ puts "Name: #{self.print_name}"
73
+ puts ""
74
+ self.print_type
75
+ puts ""
76
+ self.print_effect
77
+ puts ""
78
+ self.print_power
79
+ puts ""
80
+ self.print_pp
81
+ puts "---------------------------------------------------------"
82
+ end
83
+
84
+ def print_name
85
+ self.name.capitalize.light_red
86
+ end
87
+
88
+ def get_colored_name
89
+ self.name.capitalize.light_red
90
+ end
91
+
92
+ def print_type
93
+
94
+ puts "\tType: #{self.type.print_name(type.name)}"
95
+ end
96
+ def print_effect
97
+ puts "\tEffect: #{self.effect}"
98
+ end
99
+
100
+ def print_power
101
+ puts "\tPower: #{self.power}"
102
+ end
103
+
104
+ def print_pp
105
+ puts "\tPP: #{self.pp}"
106
+ end
107
+
108
+ def self.print_all
109
+ self.all.each{|move| move.print_all }
110
+ end
111
+
112
+
113
+ end
@@ -0,0 +1,178 @@
1
+ class MoveMenu
2
+
3
+ attr_accessor :cli
4
+
5
+ def initialize(cli)
6
+ self.cli = cli
7
+ end
8
+
9
+ def main_menu
10
+ puts "\n\n"
11
+ input = self.cli.prompt.select("What Move information would you like to get?", cycle: true) do |menu|
12
+ menu.choice 'Get a list of Moves.', 1
13
+ menu.choice 'Search for a Move by name.', 2
14
+ menu.choice 'Search for a Move by Type.', 3
15
+ menu.choice 'Get information from a random Move.', 4
16
+ menu.choice 'Return to the main menu'.light_green, 5
17
+ menu.choice 'Exit Dexter++'.light_red, 6
18
+
19
+ end
20
+
21
+ case input
22
+ when 1
23
+ self.list_moves
24
+ when 2
25
+ self.search_by_name
26
+ when 3
27
+ self.search_by_type
28
+ when 4
29
+ self.get_random
30
+ when 5
31
+ self.cli.main_menu
32
+ when 6
33
+ self.cli.exit_program
34
+ end
35
+ end
36
+
37
+ def list_moves
38
+ puts "\n\nHow many Moves would you like to list?"
39
+ input = gets.strip.to_i
40
+ until input.between?(1, Move.limit)
41
+ if input <= 0
42
+ puts"That is not enough Moves! Try a bigger number"
43
+ input = gets.strip.to_i
44
+ else
45
+ puts "Thats way too many Moves! Try a smaller number."
46
+ input = gets.strip.to_i
47
+ end
48
+ end
49
+ puts "\n\nAwesome! Let me load that for you."
50
+ puts"\n\n"
51
+ options = Move.find_with_offset_and_limit(rand(0...Move.limit), input)
52
+ self.display_move_options(options)
53
+ end
54
+
55
+ def search_by_name
56
+ puts "\n\nWhat Move would you like to search for?"
57
+ input = gets.strip.downcase
58
+ puts "\n\nAwesome! Let me load that for you."
59
+ move = API.get_move_by_name(input)
60
+ move.print_all
61
+ puts"\n\n"
62
+ self.display_more_options(move)
63
+ end
64
+
65
+ def search_by_type(type = nil)
66
+ if type
67
+ puts "\n\nAwesome! Let me load that for you."
68
+ puts "\n\n"
69
+ options = Move.find_list_by_type(type.name)
70
+ self.display_move_options(options)
71
+ else
72
+ puts "\n\n"
73
+ options = ["Normal","Flying","Poison","Ground",
74
+ "Rock","Bug","Ghost","Steel","Fire",
75
+ "Water","Grass","Electric","Psychic",
76
+ "Ice","Dragon","Dark","Fairy","Unknown",
77
+ "Shadow","Return to main menu".light_green, "Exit Dexter++".light_red]
78
+
79
+ input = self.cli.prompt.select("Select a type to search for.", options, cycle: true)
80
+ end
81
+
82
+ case input
83
+ when "Return to main menu".light_green
84
+ self.cli.main_menu
85
+ when "Exit Dexter++".light_red
86
+ self.cli.exit_program
87
+ else
88
+ puts "\n\nAwesome! Let me load that for you."
89
+ puts "\n\n"
90
+ options = Move.find_list_by_type(input.downcase)
91
+ self.display_move_options(options)
92
+ end
93
+ end
94
+
95
+ def get_random
96
+ move = API.get_random_move
97
+ move.print_all
98
+ puts"\n\n"
99
+ self.display_more_options(move)
100
+ end
101
+
102
+ def self.list_moves(num)
103
+ puts "\n\n"
104
+ input = @@prompt.select("What kind of list would you like to get?", cycle: true) do |menu|
105
+ menu.choice 'Get a list of Moves of a certain size', 1
106
+ menu.choice 'Get a list of Moves by type', 2
107
+ menu.choice 'Return to main menu'.light_green, 3
108
+ menu.choice 'Exit Dexter++'.light_red, 4
109
+ end
110
+ case input
111
+ when 1
112
+ puts "\n\nHow many Moves would you like to list?"
113
+ input = gets.strip
114
+ while !input.between?(1, Move.limit)
115
+ if input >= 0
116
+ puts"That is not enough Moves! Try a bigger number"
117
+ input = gets.strip
118
+ else
119
+ puts "Thats way too many Moves! Try a smaller number."
120
+ input = gets.strip
121
+ end
122
+ end
123
+ puts "\n\nAwesome! Let me load that for you."
124
+ puts"\n\n"
125
+ options = Move.find_list_with_offset_and_limit(rand(0...Move.limit), input)
126
+ self.display_move_options(options)
127
+ when 2
128
+ puts "\n\nWhat type of Moves would you like to list?"
129
+ puts "\n\n"
130
+ input = self.type_menu
131
+ puts "\n\nAwesome! Let me load that for you."
132
+ puts "\n\n"
133
+ options = Move.find_by_type(input.downcase)
134
+ self.display_move_options(options)
135
+ when 3
136
+ self.cli.exit_program
137
+ when 4
138
+ self.cli.main_menu
139
+ end
140
+ end
141
+
142
+ def display_move_options(options)
143
+ options.unshift("Exit Dexter++".light_red)
144
+ options.unshift("Go back to main menu".light_green)
145
+ choice = self.cli.get_menu_from_array(options)
146
+ if choice == "Exit Dexter++".light_red
147
+ self.cli.exit_program
148
+ elsif choice == "Go back to main menu".light_green
149
+ self.cli.main_menu
150
+ else move = API.get_move_by_name(choice.downcase)
151
+ move.print_all
152
+ puts "\n\n\n"
153
+ end
154
+ self.display_more_options(move)
155
+ end
156
+
157
+ def display_more_options(move)
158
+ puts "\n\n"
159
+ input = self.cli.prompt.select("What information about #{move.name.capitalize} would you like to see?", cycle: true) do |menu|
160
+ menu.choice 'Type information' , 1
161
+ menu.choice 'Go back to main menu'.light_green, 2
162
+ menu.choice 'Exit Dexter++'.light_red, 3
163
+ end
164
+ case input
165
+ when 1
166
+ move.type.print_all
167
+ puts "\n\n"
168
+ self.display_more_options(move)
169
+ when 2
170
+ self.cli.main_menu
171
+ when 3
172
+ self.cli.exit_program
173
+ end
174
+ end
175
+
176
+
177
+
178
+ end