PokemonGenerator 0.1.8 → 0.1.9
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/PokemonGenerator.gemspec +1 -0
- data/lib/PokemonGenerator.rb +31 -3
- data/lib/PokemonGenerator/version.rb +1 -1
- data/spec/PokemonGenerator_spec.rb +38 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 488312442632ce603eaace60e1d4a8445c2f68e2
|
4
|
+
data.tar.gz: 4f7b2694f15696cffdb6863aaaa197b6cce991d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6051b167250b53651637a1d8195f03f458ff07d5a87870a4c58964d84cbf110e7fca57bb62e6d48bd9769dfa5068eebe1682a77978738fc76dbbedca4f4ed007
|
7
|
+
data.tar.gz: f151d36d81270d00bf2de3c78e139cf9afa3ad54e8e32fa710c8928cd7005e24a7c76e25bbba8fd034217bafff615f14e3b9c2f13c766e4e8d2b77a1a3025be5
|
data/PokemonGenerator.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
the moves for that specific pokemon by its name a easy to work with array.
|
19
19
|
If you wish to learn more on how to PokemonGenerator Gem please visit
|
20
20
|
my Homepage."
|
21
|
+
|
21
22
|
spec.homepage = "https://github.com/collinL34/PokemonGeneratorGem"
|
22
23
|
spec.license = "MIT"
|
23
24
|
|
data/lib/PokemonGenerator.rb
CHANGED
@@ -19,7 +19,7 @@ module PokemonGenerator
|
|
19
19
|
types_list.length == 2 ? types_list[1] : [types_list[1], types_list[2]]
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
22
|
+
def self.link_html_stripper(pokmn_name)
|
23
23
|
html = PokemonGenerator.nokogiri_obj()
|
24
24
|
html.css('tr td .ent-name').find do |pokmn|
|
25
25
|
return pokmn.attributes['href'].text if pokmn.text == pokmn_name
|
@@ -39,7 +39,7 @@ module PokemonGenerator
|
|
39
39
|
|
40
40
|
def self.moves(pokmn_name)
|
41
41
|
moves_list = []
|
42
|
-
pokmn_link = PokemonGenerator.
|
42
|
+
pokmn_link = PokemonGenerator.link_html_stripper(pokmn_name)
|
43
43
|
html = Nokogiri::HTML(open("https://pokemondb.net/#{pokmn_link}"))
|
44
44
|
html.css('td').each do |pokmn_txt|
|
45
45
|
moves = pokmn_txt.css('.ent-name').text
|
@@ -48,6 +48,29 @@ module PokemonGenerator
|
|
48
48
|
moves_list
|
49
49
|
end
|
50
50
|
|
51
|
+
def self.evolve(pokemon_to_evolve)
|
52
|
+
evolutions = []
|
53
|
+
href = link_html_stripper(pokemon_to_evolve)
|
54
|
+
html = Nokogiri::HTML(open("https://pokemondb.net/#{href}"))
|
55
|
+
html.css('.infocard-tall').each do |pokmn|
|
56
|
+
if pokmn.css('.ent-name').text != ''
|
57
|
+
evolutions << pokmn.css('.ent-name').text
|
58
|
+
end
|
59
|
+
end
|
60
|
+
if !evolutions.empty?
|
61
|
+
PokemonGenerator.pokemon({ name: evolutions[evolutions.index(pokemon_to_evolve) + 1] })
|
62
|
+
else
|
63
|
+
"Their is no evolution for that pokemon."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.image(pokmn_name)
|
68
|
+
pokmn_link = PokemonGenerator.link_html_stripper(pokmn_name.capitalize)
|
69
|
+
html = Nokogiri::HTML(open("https://pokemondb.net/#{pokmn_link}"))
|
70
|
+
html.css('.figure img').attr('src').text == "https://img.pokemondb.net/s.png" ?
|
71
|
+
'Sorry no image found by that name' : html.css('.figure img').attr('src').text
|
72
|
+
end
|
73
|
+
|
51
74
|
def self.pokemon_name_specific(pokemon_list, name)
|
52
75
|
if pokemon_list != ''
|
53
76
|
pokemon_list.find do |pokmn|
|
@@ -55,11 +78,13 @@ module PokemonGenerator
|
|
55
78
|
return {
|
56
79
|
name: name,
|
57
80
|
type: PokemonGenerator.type_stripper(pokmn.css('a')),
|
58
|
-
|
81
|
+
image: PokemonGenerator.image(pokmn.css('.ent-name').text),
|
82
|
+
moves: PokemonGenerator.moves(name.capitalize)
|
59
83
|
}
|
60
84
|
end
|
61
85
|
end
|
62
86
|
end
|
87
|
+
'Sorry no pokemon found by that name.'
|
63
88
|
end
|
64
89
|
|
65
90
|
def self.pokemon_type_specific(pokemon_list, type)
|
@@ -68,10 +93,12 @@ module PokemonGenerator
|
|
68
93
|
return {
|
69
94
|
name: pokmn.css('.ent-name').text,
|
70
95
|
type: PokemonGenerator.type_stripper(pokmn.css('a')),
|
96
|
+
image: PokemonGenerator.image(pokmn.css('.ent-name').text),
|
71
97
|
moves: PokemonGenerator.moves(pokmn.css('.ent-name').text)
|
72
98
|
}
|
73
99
|
end
|
74
100
|
end
|
101
|
+
'Sorry no pokemon found by that type.'
|
75
102
|
end
|
76
103
|
|
77
104
|
|
@@ -87,6 +114,7 @@ module PokemonGenerator
|
|
87
114
|
pokemon = pokemon_list[rand(0..909)]
|
88
115
|
pokemon_obj[:name] = pokemon.css('.ent-name').text
|
89
116
|
pokemon_obj[:type] = PokemonGenerator.type_stripper(pokemon.css('a'))
|
117
|
+
pokemon_obj[:image] = PokemonGenerator.image(pokemon.css('.ent-name').text)
|
90
118
|
pokemon_obj[:moves] = PokemonGenerator.moves(pokemon.css('.ent-name').text)
|
91
119
|
end
|
92
120
|
pokemon_obj
|
@@ -9,19 +9,21 @@ RSpec.describe PokemonGenerator do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'Pokemon' do
|
12
|
-
it 'returns
|
12
|
+
it 'returns an error when given a wrong name for a pokemon' do
|
13
|
+
expect(PokemonGenerator.pokemon({name: 'bulbasar'})).to eq 'Sorry no pokemon found by that name.'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns an error when given a wrong type for a pokemon' do
|
17
|
+
expect(PokemonGenerator.pokemon({type: 'bulbasar'})).to eq 'Sorry no pokemon found by that type.'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns a randomized hash specifiying a pokemon name, moves and type' do
|
13
21
|
expect(PokemonGenerator.pokemon()).to be_a Hash
|
14
22
|
end
|
15
23
|
|
16
24
|
it 'returns the correct pokemon with the specific type' do
|
17
25
|
expect(PokemonGenerator.pokemon({type: 'Fire'})).to be_a Hash
|
18
26
|
end
|
19
|
-
|
20
|
-
it 'returns an array and not an object for moves list' do
|
21
|
-
moves = PokemonGenerator.moves({type: 'Water'})
|
22
|
-
pokmn = PokemonGenerator.pokemon({type: 'Water'})
|
23
|
-
expect(moves).not_to eq(pokmn)
|
24
|
-
end
|
25
27
|
|
26
28
|
it 'returns the correct pokemon with non capitalized name' do
|
27
29
|
expect(PokemonGenerator.pokemon({name: 'bulbasaur'})).to be_a Hash
|
@@ -31,33 +33,55 @@ RSpec.describe PokemonGenerator do
|
|
31
33
|
describe 'Name' do
|
32
34
|
it 'returns a random named pokemon' do
|
33
35
|
# 100.times { expect(PokemonGenerator.name).to be_a String }
|
34
|
-
expect(PokemonGenerator.name).to be_a String
|
36
|
+
expect(PokemonGenerator.name()).to be_a String
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
40
|
describe 'Type' do
|
39
41
|
it 'returns a randomized pokemon type' do
|
40
42
|
# 100.times { expect(PokemonGenerator.type[0]).to be_a String }
|
41
|
-
expect(PokemonGenerator.type[0]).to be_a String
|
43
|
+
expect(PokemonGenerator.type()[0]).to be_a String
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
describe 'Moves' do
|
46
|
-
|
47
|
-
it 'returns a selected list of array of moves for the specific pokemon' do
|
47
|
+
describe 'Moves' do
|
48
|
+
it 'returns a selected list of array of moves for the specific pokemon' do
|
48
49
|
expect(PokemonGenerator.moves({name: 'Venusaur'})).to be_a Array
|
49
50
|
end
|
50
51
|
|
51
|
-
it 'returns the moves for the
|
52
|
+
it 'returns the correct moves for the pokemon' do
|
52
53
|
squirtle = PokemonGenerator.pokemon( {name: 'Squirtle'} )
|
53
54
|
moves = PokemonGenerator.moves('Squirtle')
|
54
55
|
expect(squirtle[:moves]).to eq moves
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
|
+
describe 'image' do
|
60
|
+
it 'returns an image url' do
|
61
|
+
expect(PokemonGenerator.image('Bulbasaur')).to be_a String
|
62
|
+
end
|
59
63
|
|
64
|
+
it 'returns an image url when given a lower case name' do
|
65
|
+
expect(PokemonGenerator.image('bulbasaur')).to be_a String
|
66
|
+
end
|
60
67
|
|
68
|
+
it 'returns an error when given wrong pokemon name' do
|
69
|
+
expect(PokemonGenerator.image('Bulbasar')).to eq 'Sorry no image found by that name'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'evolve' do
|
74
|
+
it 'returns the hash of the next evolution' do
|
75
|
+
expect(PokemonGenerator.evolve('Squirtle')).to be_a Hash
|
76
|
+
end
|
61
77
|
|
78
|
+
it 'returns the name of the next evolution' do
|
79
|
+
expect(PokemonGenerator.evolve('Squirtle')[:name]).to eq 'Wartortle'
|
80
|
+
end
|
62
81
|
|
82
|
+
it 'returns a string telling the user an error occured' do
|
83
|
+
expect(PokemonGenerator.evolve('Larpras')).to eq "Their is no evolution for that pokemon."
|
84
|
+
end
|
85
|
+
end
|
63
86
|
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PokemonGenerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- collinl34
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.6.
|
112
|
+
rubygems_version: 2.6.8
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Pokemon generator to quickely generate real pokemon and their specific moves.
|