smogon 0.6.2 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smogon.rb +3 -2
- data/lib/smogon/abilitydex.rb +4 -21
- data/lib/smogon/api.rb +34 -14
- data/lib/smogon/itemdex.rb +4 -21
- data/lib/smogon/movedex.rb +4 -29
- data/lib/smogon/movesetdex.rb +19 -52
- data/lib/smogon/pokedex.rb +5 -39
- data/lib/smogon/types/ability.rb +8 -8
- data/lib/smogon/types/base.rb +52 -0
- data/lib/smogon/types/item.rb +8 -8
- data/lib/smogon/types/move.rb +8 -12
- data/lib/smogon/types/moveset.rb +23 -13
- data/lib/smogon/types/pokemon.rb +32 -18
- data/lib/smogon/version.rb +2 -2
- data/spec/abilitydex.rb +1 -1
- data/spec/itemdex.rb +1 -1
- data/spec/movedex.rb +1 -1
- data/spec/movesetdex.rb +4 -5
- data/spec/pokedex.rb +4 -3
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5efd122754905b76c20a3a36163bd0ff435e5119
|
4
|
+
data.tar.gz: ddff2489eeff93a416e6c4cfac04346d198c21d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7256f3c29f5518b996825fe08e385d56e715f17705a07c9483adf7e97831ad922495c6ffd8d7cd2fee78866081ee9bfbcbc1e83693c08ba0959f4b0d4d31d60c
|
7
|
+
data.tar.gz: '082911c49504411c00ffbef753a067f5b2a2105dbc5ac0dcdc1b4f8cddd30dd120c09431b43fe1fa454fe9d742d35b315cf31a4d31fc9dd7ccfe065fc97a43c2'
|
data/lib/smogon.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -17,12 +17,13 @@
|
|
17
17
|
# along with Smogon-API. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
|
20
|
-
require '
|
20
|
+
require 'net/http'
|
21
21
|
require 'json'
|
22
22
|
|
23
23
|
require 'smogon/api'
|
24
24
|
require 'smogon/naturedex'
|
25
25
|
|
26
|
+
require 'smogon/types/base'
|
26
27
|
require 'smogon/types/pokemon'
|
27
28
|
require 'smogon/types/ability'
|
28
29
|
require 'smogon/types/item'
|
data/lib/smogon/abilitydex.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,26 +19,9 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Abilitydex
|
22
|
-
def self.get(name
|
23
|
-
|
24
|
-
|
25
|
-
fields ||= [
|
26
|
-
'name',
|
27
|
-
'alias',
|
28
|
-
'description'
|
29
|
-
]
|
30
|
-
|
31
|
-
response = API.request 'ability', name, fields
|
32
|
-
return nil if response.is_a?(String) || response.empty? || response.first.empty?
|
33
|
-
return response if not incapsulate
|
34
|
-
|
35
|
-
response = response.first
|
36
|
-
|
37
|
-
Ability.new.tap do |ability|
|
38
|
-
ability.name = response['name' ]
|
39
|
-
ability._name = response['alias' ]
|
40
|
-
ability.description = response['description']
|
41
|
-
end
|
22
|
+
def self.get(name)
|
23
|
+
response = API.request(:abilities, name)
|
24
|
+
Type::Ability.new(response)
|
42
25
|
end
|
43
26
|
end
|
44
27
|
end
|
data/lib/smogon/api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,20 +19,30 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class API
|
22
|
-
METAGAME = '
|
23
|
-
ENDPOINT = 'http://www.smogon.com/dex/
|
22
|
+
METAGAME = 'sm'
|
23
|
+
ENDPOINT = 'http://www.smogon.com/dex/_rpc/dump-'.freeze
|
24
24
|
|
25
25
|
class << self
|
26
|
-
def request(what, name,
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
def request(what, name, remote = false)
|
27
|
+
name = aliasize(name)
|
28
|
+
|
29
|
+
if remote
|
30
|
+
return JSON.parse(req(
|
31
|
+
URI(ENDPOINT + what.to_s),
|
32
|
+
{ gen: METAGAME, alias: name }
|
33
|
+
))
|
34
|
+
end
|
35
|
+
|
36
|
+
unless @_basics
|
37
|
+
@_basics = JSON.parse(req(
|
38
|
+
URI(ENDPOINT + 'basics'),
|
39
|
+
{ gen: METAGAME }
|
40
|
+
))
|
41
|
+
end
|
42
|
+
|
43
|
+
@_basics[what.to_s].find do |x|
|
44
|
+
aliasize(x['name']) == name
|
45
|
+
end
|
36
46
|
end
|
37
47
|
|
38
48
|
def using_metagame(metagame, &block)
|
@@ -43,11 +53,21 @@ module Smogon
|
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
46
|
-
|
56
|
+
private
|
47
57
|
|
48
58
|
def aliasize(string)
|
49
59
|
string.downcase.gsub(' ', '_').gsub(/[^a-z0-9_\-]/i, '')
|
50
60
|
end
|
61
|
+
|
62
|
+
def req(uri, body)
|
63
|
+
request = Net::HTTP::Post.new(uri)
|
64
|
+
request.body = body.to_json
|
65
|
+
request.content_type = 'application/json; charset=utf-8'
|
66
|
+
|
67
|
+
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
68
|
+
http.request(request)
|
69
|
+
end.body
|
70
|
+
end
|
51
71
|
end
|
52
72
|
end
|
53
73
|
end
|
data/lib/smogon/itemdex.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,26 +19,9 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Itemdex
|
22
|
-
def self.get(name,
|
23
|
-
|
24
|
-
|
25
|
-
fields ||= [
|
26
|
-
'name',
|
27
|
-
'alias',
|
28
|
-
'description'
|
29
|
-
]
|
30
|
-
|
31
|
-
response = API.request 'item', name, fields
|
32
|
-
return nil if response.is_a?(String) || response.empty? || response.first.empty?
|
33
|
-
return response if not incapsulate
|
34
|
-
|
35
|
-
response = response.first
|
36
|
-
|
37
|
-
Item.new.tap do |item|
|
38
|
-
item.name = response['name' ]
|
39
|
-
item._name = response['alias' ]
|
40
|
-
item.description = response['description']
|
41
|
-
end
|
22
|
+
def self.get(name, incapsulate = true)
|
23
|
+
response = API.request(:items, name)
|
24
|
+
Type::Item.new(response)
|
42
25
|
end
|
43
26
|
end
|
44
27
|
end
|
data/lib/smogon/movedex.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,34 +19,9 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Movedex
|
22
|
-
def self.get(name
|
23
|
-
|
24
|
-
|
25
|
-
fields ||= [
|
26
|
-
'name',
|
27
|
-
'alias',
|
28
|
-
'description',
|
29
|
-
'power',
|
30
|
-
'accuracy',
|
31
|
-
'pp',
|
32
|
-
'type' => ['name'],
|
33
|
-
]
|
34
|
-
|
35
|
-
response = API.request 'move', name, fields
|
36
|
-
return nil if response.is_a?(String) || response.empty? || response.first.empty?
|
37
|
-
return response if not incapsulate
|
38
|
-
|
39
|
-
response = response.first
|
40
|
-
|
41
|
-
Move.new.tap do |move|
|
42
|
-
move.name = response['name' ]
|
43
|
-
move._name = response['alias' ]
|
44
|
-
move.description = response['description']
|
45
|
-
move.type = response['type' ].values.join(' / ')
|
46
|
-
move.power = response['power' ]
|
47
|
-
move.accuracy = response['accuracy' ]
|
48
|
-
move.pp = response['pp' ]
|
49
|
-
end
|
22
|
+
def self.get(name)
|
23
|
+
response = API.request(:moves, name)
|
24
|
+
Type::Move.new(response)
|
50
25
|
end
|
51
26
|
end
|
52
27
|
end
|
data/lib/smogon/movesetdex.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,67 +19,34 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Movesetdex
|
22
|
-
def self.get(name, tier = nil, metagame = nil
|
23
|
-
incapsulate = fields == nil
|
24
|
-
|
25
|
-
fields ||= [
|
26
|
-
'name',
|
27
|
-
'movesets' => [
|
28
|
-
'name',
|
29
|
-
{ 'tags' => %w(shorthand) },
|
30
|
-
{ 'items' => %w(name) },
|
31
|
-
{ 'abilities' => %w(name) },
|
32
|
-
{ 'natures' => %w(hp patk pdef spatk spdef spe) },
|
33
|
-
{ 'moveslots' => [ 'slot', { 'move' => %(name) } ] },
|
34
|
-
{ 'evconfigs' => %w(hp patk pdef spatk spdef spe) }
|
35
|
-
]
|
36
|
-
]
|
37
|
-
|
22
|
+
def self.get(name, tier = nil, metagame = nil)
|
38
23
|
response = if metagame
|
39
|
-
API.using_metagame(metagame) do
|
40
|
-
API.request
|
24
|
+
API.using_metagame(metagame.downcase) do
|
25
|
+
API.request(:pokemon, name, true)
|
41
26
|
end
|
42
27
|
else
|
43
|
-
API.request
|
28
|
+
API.request(:pokemon, name, true)
|
44
29
|
end
|
45
|
-
return nil if response.is_a?(String) || response.empty? || response.first.empty?
|
46
|
-
return response if not incapsulate
|
47
30
|
|
48
|
-
|
31
|
+
strategies = response['strategies']
|
49
32
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
moveset.tier = movesetdex['tags'][0]['shorthand']
|
56
|
-
moveset.item = movesetdex['items'].collect(&:values).flatten
|
57
|
-
moveset.ability = movesetdex['abilities'].collect(&:values).flatten
|
58
|
-
moveset.nature = movesetdex['natures'].map { |nature| Naturedex.get(nature) }
|
59
|
-
|
60
|
-
moveset.moves = []
|
61
|
-
movesetdex['moveslots'].each do |moveslot|
|
62
|
-
slot = moveslot['slot'] - 1
|
33
|
+
if (tier = tier&.upcase)
|
34
|
+
strategies = [strategies.find do |strategy|
|
35
|
+
strategy['format'] == tier
|
36
|
+
end]
|
37
|
+
end
|
63
38
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
39
|
+
[].tap do |movesets|
|
40
|
+
strategies.each do |strategy|
|
41
|
+
# overview, comments
|
42
|
+
tier = strategy['format']
|
43
|
+
movesets.concat(
|
44
|
+
strategy['movesets'].map do |moveset|
|
45
|
+
Type::Moveset.new(name, tier, moveset)
|
69
46
|
end
|
70
|
-
|
71
|
-
moveset.evs = [].tap do |evs|
|
72
|
-
evconfigs = movesetdex['evconfigs'].first
|
73
|
-
|
74
|
-
['hp', 'patk', 'pdef', 'spatk', 'spdef', 'spe'].each do |stat|
|
75
|
-
evs << evconfigs[stat]
|
76
|
-
end if evconfigs
|
77
|
-
end.join ' / '
|
78
|
-
end
|
47
|
+
)
|
79
48
|
end
|
80
49
|
end
|
81
|
-
|
82
|
-
tier ? results.reject { |moveset| moveset.tier.downcase != tier.downcase } : results
|
83
50
|
end
|
84
51
|
end
|
85
52
|
end
|
data/lib/smogon/pokedex.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -19,44 +19,10 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Pokedex
|
22
|
-
def self.get(name
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
'name',
|
27
|
-
'alias',
|
28
|
-
'alts' => [
|
29
|
-
{ 'types' => %w(name) },
|
30
|
-
{ 'tags' => %w(shorthand) },
|
31
|
-
{ 'abilities' => %w(name) },
|
32
|
-
'hp', 'patk', 'pdef', 'spatk', 'spdef', 'spe'
|
33
|
-
],
|
34
|
-
'moves' => ['name']
|
35
|
-
]
|
36
|
-
|
37
|
-
response = API.request 'pokemon', name, fields
|
38
|
-
return nil if response.is_a?(String) || response.empty? || response.first.empty?
|
39
|
-
return response if not incapsulate
|
40
|
-
|
41
|
-
response = response.first
|
42
|
-
pokedex = response['alts'][0]
|
43
|
-
|
44
|
-
Pokemon.new.tap do |pokemon|
|
45
|
-
pokemon.name = response['name']
|
46
|
-
pokemon._name = response['alias']
|
47
|
-
|
48
|
-
pokemon.types = pokedex['types'].collect(&:values).flatten
|
49
|
-
pokemon.tier = pokedex['tags'][0]['shorthand']
|
50
|
-
pokemon.abilities = pokedex['abilities'].collect(&:values).flatten
|
51
|
-
|
52
|
-
pokemon.base_stats = [].tap do |base_stats|
|
53
|
-
['hp', 'patk', 'pdef', 'spatk', 'spdef', 'spe'].each do |stat|
|
54
|
-
base_stats << pokedex[stat]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
pokemon.moves = response['moves'].collect(&:values).flatten
|
59
|
-
end
|
22
|
+
def self.get(name)
|
23
|
+
response = API.request(:pokemon, name)
|
24
|
+
moves = API.request(:pokemon, name, true)['learnset']
|
25
|
+
Type::Pokemon.new(response, moves)
|
60
26
|
end
|
61
27
|
end
|
62
28
|
end
|
data/lib/smogon/types/ability.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -18,15 +18,15 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
module Smogon
|
21
|
-
|
22
|
-
|
21
|
+
module Type
|
22
|
+
class Ability < Base
|
23
|
+
ATTRIBUTES = %w(
|
24
|
+
name description gen_family
|
25
|
+
).freeze
|
23
26
|
|
24
|
-
|
25
|
-
"Name: #{@name}\nDescription: #{@description}"
|
26
|
-
end
|
27
|
+
attr_accessor(*ATTRIBUTES)
|
27
28
|
|
28
|
-
|
29
|
-
"http://www.smogon.com/dex/#{API::METAGAME}/abilities/#{@_name}"
|
29
|
+
TYPE = 'abilities'.freeze
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
|
+
#
|
4
|
+
# This file is part of Smogon-API.
|
5
|
+
#
|
6
|
+
# Smogon-API is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Smogon-API is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Smogon-API. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Smogon
|
21
|
+
module Type
|
22
|
+
class Base
|
23
|
+
def initialize(response)
|
24
|
+
attributes.each do |attr|
|
25
|
+
public_send("#{attr}=", response[attr])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_h
|
30
|
+
attributes.zip(
|
31
|
+
attributes.map { |attr| public_send(attr) }
|
32
|
+
).to_h
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
attributes.map do |attr|
|
37
|
+
"#{attr.capitalize}: #{public_send(attr)}"
|
38
|
+
end.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def url
|
42
|
+
"http://www.smogon.com/dex/#{::Smogon::API::METAGAME}/#{self.class::TYPE}/#{name}"
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def attributes
|
48
|
+
self.class::ATTRIBUTES
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/smogon/types/item.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -18,15 +18,15 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
module Smogon
|
21
|
-
|
22
|
-
|
21
|
+
module Type
|
22
|
+
class Item < Base
|
23
|
+
ATTRIBUTES = %w(
|
24
|
+
name description gen_family
|
25
|
+
).freeze
|
23
26
|
|
24
|
-
|
25
|
-
"Name: #{@name}\nDescription: #{@description}"
|
26
|
-
end
|
27
|
+
attr_accessor(*ATTRIBUTES)
|
27
28
|
|
28
|
-
|
29
|
-
"http://www.smogon.com/dex/#{API::METAGAME}/items/#{@_name}"
|
29
|
+
TYPE = 'items'.freeze
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/smogon/types/move.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -18,19 +18,15 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
module Smogon
|
21
|
-
|
22
|
-
|
21
|
+
module Type
|
22
|
+
class Move < Base
|
23
|
+
ATTRIBUTES = %w(
|
24
|
+
name category power accuracy pp description type genfamily
|
25
|
+
).freeze
|
23
26
|
|
24
|
-
|
25
|
-
"Name: #{@name}\nDescription: #{@description}\nType: #{@type}\nPower: #{@power}\nAccuracy: #{@accuracy}\nPP: #{@pp}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def url
|
29
|
-
"http://www.smogon.com/dex/#{API::METAGAME}/moves/#{@_name}"
|
30
|
-
end
|
27
|
+
attr_accessor(*ATTRIBUTES)
|
31
28
|
|
32
|
-
|
33
|
-
define_method(m) { '' }
|
29
|
+
TYPE = 'moves'.freeze
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
data/lib/smogon/types/moveset.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
#--
|
3
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
4
3
|
#
|
5
4
|
# This file is part of Smogon-API.
|
6
5
|
#
|
@@ -19,19 +18,30 @@
|
|
19
18
|
#++
|
20
19
|
|
21
20
|
module Smogon
|
22
|
-
|
23
|
-
|
21
|
+
module Type
|
22
|
+
class Moveset < Base
|
23
|
+
ATTRIBUTES = %w(
|
24
|
+
pokemon name tier items abilities natures moves evs ivs
|
25
|
+
).freeze
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
attr_accessor(*ATTRIBUTES)
|
28
|
+
|
29
|
+
def initialize(pokemon, tier, moveset)
|
30
|
+
@pokemon = pokemon
|
31
|
+
@name = moveset['name']
|
32
|
+
# @description = moveset['description']
|
33
|
+
@tier = tier
|
34
|
+
@items = moveset['items']
|
35
|
+
@abilities = moveset['abilities']
|
36
|
+
@natures = moveset['natures']
|
37
|
+
@moves = moveset['moveslots']
|
38
|
+
@evs = moveset['evconfigs'].map(&:values)
|
39
|
+
@ivs = moveset['ivconfigs'].map(&:values)
|
40
|
+
end
|
32
41
|
|
33
|
-
|
34
|
-
|
42
|
+
def url
|
43
|
+
"http://www.smogon.com/dex/#{::Smogon::API::METAGAME}/pokemon/#{pokemon}"
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
data/lib/smogon/types/pokemon.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -18,23 +18,37 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
module Smogon
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
21
|
+
module Type
|
22
|
+
class Pokemon < Base
|
23
|
+
ATTRIBUTES = %w(
|
24
|
+
name base_stats weight height types abilities evolutions genfamily moves
|
25
|
+
).freeze
|
26
|
+
|
27
|
+
attr_accessor(*ATTRIBUTES)
|
28
|
+
|
29
|
+
TYPE = 'pokemon'.freeze
|
30
|
+
STATS = %w(hp atk def spa spd spe).freeze
|
31
|
+
|
32
|
+
def initialize(response, moves)
|
33
|
+
@name = response['name']
|
34
|
+
@evolutions = response['evos']
|
35
|
+
@genfamily = response['genfamily']
|
36
|
+
@moves = moves
|
37
|
+
|
38
|
+
alts = response['alts'][0]
|
39
|
+
@base_stats = alts.fetch_values(*STATS)
|
40
|
+
@weight = alts['weight']
|
41
|
+
@height = alts['height']
|
42
|
+
@abilities = alts['abilities']
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.id2name(id)
|
46
|
+
begin
|
47
|
+
Nokogiri::HTML(open("http://www.marriland.com/pokedex/#{id}")).xpath('//div[@class="overview"]/h2')[0].text
|
48
|
+
rescue
|
49
|
+
nil
|
50
|
+
end
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|
40
|
-
end
|
54
|
+
end
|
data/lib/smogon/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright(C)
|
2
|
+
# Copyright(C) 2017 Giovanni Capuano <webmaster@giovannicapuano.net>
|
3
3
|
#
|
4
4
|
# This file is part of Smogon-API.
|
5
5
|
#
|
@@ -18,5 +18,5 @@
|
|
18
18
|
#++
|
19
19
|
|
20
20
|
module Smogon
|
21
|
-
VERSION = '0.
|
21
|
+
VERSION = '0.7'
|
22
22
|
end
|
data/spec/abilitydex.rb
CHANGED
@@ -3,7 +3,7 @@ require 'smogon'
|
|
3
3
|
|
4
4
|
describe 'Abilitydex' do
|
5
5
|
it 'returns infos about the given ability' do
|
6
|
-
ability = Smogon::Abilitydex.get
|
6
|
+
ability = Smogon::Abilitydex.get('Synchronize')
|
7
7
|
|
8
8
|
expect(ability.name).to eq('Synchronize')
|
9
9
|
expect(ability.description.length).to be > 10
|
data/spec/itemdex.rb
CHANGED
data/spec/movedex.rb
CHANGED
data/spec/movesetdex.rb
CHANGED
@@ -3,15 +3,14 @@ require 'smogon'
|
|
3
3
|
|
4
4
|
describe 'Movesetdex' do
|
5
5
|
it 'returns the moveset of given Pokémon and metagame' do
|
6
|
-
movesets = Smogon::Movesetdex.get
|
6
|
+
movesets = Smogon::Movesetdex.get('Abomasnow', 'UU', 'bw')
|
7
7
|
|
8
|
-
expect(movesets.
|
9
|
-
expect(movesets.
|
10
|
-
expect(movesets.first.nature.include?('Lonely')).to be_truthy
|
8
|
+
expect(movesets.count).to eq 2
|
9
|
+
expect(movesets.first.natures).to eq(%w(Sassy Calm))
|
11
10
|
expect(movesets.select { |moveset| moveset.tier != 'UU' }.length).to be 0
|
12
11
|
end
|
13
12
|
|
14
13
|
it 'returns the moveset of given Pokémon and metagame having some empty field' do
|
15
|
-
Smogon::Movesetdex.get 'Metagross', 'OU', '
|
14
|
+
Smogon::Movesetdex.get 'Metagross', 'OU', 'XY'
|
16
15
|
end
|
17
16
|
end
|
data/spec/pokedex.rb
CHANGED
@@ -3,21 +3,22 @@ require 'smogon'
|
|
3
3
|
|
4
4
|
describe 'Pokedex' do
|
5
5
|
it 'returns the requested Pokémon' do
|
6
|
-
pokemon = Smogon::Pokedex.get
|
6
|
+
pokemon = Smogon::Pokedex.get('Blaziken')
|
7
7
|
|
8
8
|
expect(pokemon.name).to eq('Blaziken')
|
9
9
|
expect(pokemon.base_stats.last).to be 80
|
10
10
|
expect(pokemon.moves.length).to be > 10
|
11
11
|
expect(pokemon.to_s.length).to be > 10
|
12
|
+
expect(pokemon.url).to eq 'http://www.smogon.com/dex/sm/pokemon/Blaziken'
|
12
13
|
end
|
13
14
|
|
14
15
|
it 'returns the requested Pokémon containing special chars' do
|
15
|
-
pokemon = Smogon::Pokedex.get
|
16
|
+
pokemon = Smogon::Pokedex.get('Porygon-Z')
|
16
17
|
expect(pokemon.name).to eq('Porygon-Z')
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'returns the requested Pokémon containing numbers' do
|
20
|
-
pokemon = Smogon::Pokedex.get
|
21
|
+
pokemon = Smogon::Pokedex.get('Porygon2')
|
21
22
|
expect(pokemon.name).to eq('Porygon2')
|
22
23
|
end
|
23
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smogon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.6'
|
55
55
|
description: APIs wrapper to get (Poké|Ability|Item|Move|Moveset)dex data from Smogon
|
56
56
|
email: webmaster@giovannicapuano.net
|
57
57
|
executables: []
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/smogon/naturedex.rb
|
68
68
|
- lib/smogon/pokedex.rb
|
69
69
|
- lib/smogon/types/ability.rb
|
70
|
+
- lib/smogon/types/base.rb
|
70
71
|
- lib/smogon/types/item.rb
|
71
72
|
- lib/smogon/types/move.rb
|
72
73
|
- lib/smogon/types/moveset.rb
|
@@ -79,7 +80,7 @@ files:
|
|
79
80
|
- spec/pokedex.rb
|
80
81
|
homepage: http://www.giovannicapuano.net
|
81
82
|
licenses:
|
82
|
-
- GPL-3
|
83
|
+
- GPL-3.0
|
83
84
|
metadata: {}
|
84
85
|
post_install_message:
|
85
86
|
rdoc_options: []
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.6.12
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: APIs wrapper to get data from Smogon.
|