smogon 0.2.1 → 0.3
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 +8 -8
- data/lib/smogon.rb +4 -2
- data/lib/smogon/abilitydex.rb +2 -2
- data/lib/smogon/movedex.rb +29 -45
- data/lib/smogon/movesetdex.rb +81 -0
- data/lib/smogon/{moveset.rb → types/move.rb} +6 -4
- data/lib/smogon/version.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWFhYzlhYmU0YTU4OGM3OTAxMWNlODg3MTFjZDk2ZTZmNTJjNDA1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmRlMzZmOTA3YjY4MTJkNzdjNmEwOTAxNTBjMjBjZjE1NjJlNzIwNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWU0MDJiMjY1ZTFjOTJhN2FiNGE1MzA5OTQ2ZjI3NmVmMzFhMWY4YzI4ZmMx
|
10
|
+
MzNjZTlhYTlmZTkwZGNmZDM0ZGUxZDAzMmI5MjAwYmNhNmExZDlhZTU2ZGRj
|
11
|
+
NTIyYTBlOWVlYWQ0NTAyZGQ0NWU2MzNmNmFjZjNiOTU5NjcxYWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzllMjg4MGEzNmE5Mjg5NzA3ZDYwZWIxNWUxMjMyNjMzYjJhYzM0NGQwNTA4
|
14
|
+
ZTgyMjg4NzkwNGVkMjJiZTk5YzU0Y2QzMzgxMjNmMzBmZDE3NGEyMDk4OThi
|
15
|
+
NDU0ZTNiNmI2YzFhMGVjZTFkYjVjNDY5NGE0NjFkY2E2ZmFhMDI=
|
data/lib/smogon.rb
CHANGED
@@ -21,11 +21,13 @@ require 'open-uri'
|
|
21
21
|
require 'nokogiri'
|
22
22
|
|
23
23
|
require 'smogon/types/pokemon'
|
24
|
-
require 'smogon/types/moveset'
|
25
24
|
require 'smogon/types/ability'
|
25
|
+
require 'smogon/types/move'
|
26
|
+
require 'smogon/types/moveset'
|
26
27
|
|
27
28
|
require 'smogon/pokedex'
|
28
|
-
require 'smogon/movedex'
|
29
29
|
require 'smogon/abilitydex'
|
30
|
+
require 'smogon/movedex'
|
31
|
+
require 'smogon/movesetdex'
|
30
32
|
|
31
33
|
require 'smogon/version'
|
data/lib/smogon/abilitydex.rb
CHANGED
@@ -21,7 +21,7 @@ module Smogon
|
|
21
21
|
class Abilitydex
|
22
22
|
def self.get(name)
|
23
23
|
begin
|
24
|
-
name = name.downcase.gsub
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
25
|
url = URI::encode "http://www.smogon.com/bw/abilities/#{name}"
|
26
26
|
|
27
27
|
smogon = Nokogiri::HTML(open(url))
|
@@ -49,4 +49,4 @@ module Smogon
|
|
49
49
|
return ability
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
data/lib/smogon/movedex.rb
CHANGED
@@ -19,63 +19,47 @@
|
|
19
19
|
|
20
20
|
module Smogon
|
21
21
|
class Movedex
|
22
|
-
def self.get(name
|
22
|
+
def self.get(name)
|
23
23
|
begin
|
24
|
-
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
|
+
url = URI::encode "http://www.smogon.com/bw/moves/#{name}"
|
25
26
|
|
26
27
|
smogon = Nokogiri::HTML(open(url))
|
27
28
|
rescue
|
28
29
|
return nil
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
+
move = Move.new
|
32
33
|
|
33
|
-
smogon.xpath('//
|
34
|
-
|
35
|
-
|
36
|
-
moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
|
37
|
-
moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
|
38
|
-
moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
|
39
|
-
|
40
|
-
s.xpath('.//a').each { |a|
|
41
|
-
(moveset.item ||= []) << a.text if a['href'].include? '/items/'
|
42
|
-
(moveset.ability ||= []) << a.text if a['href'].include? '/abilities/'
|
43
|
-
(moveset.nature ||= []) << a.text if a['href'].include? '/natures/'
|
44
|
-
}
|
45
|
-
|
46
|
-
movesets << moveset
|
47
|
-
}
|
34
|
+
move.name = smogon.xpath('//div[@id="content_wrapper"]/h1').first.text
|
35
|
+
move._name = name
|
48
36
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
a = a.gsub(/\n?/, '').strip
|
56
|
-
if a == ?~
|
57
|
-
continue = false
|
58
|
-
elsif a == ?/
|
59
|
-
continue = true
|
60
|
-
elsif a.empty?
|
37
|
+
move.description = ''.tap { |d|
|
38
|
+
h2 = 0
|
39
|
+
ul = 0
|
40
|
+
smogon.xpath('//div[@id="content_wrapper"]').children.each { |c|
|
41
|
+
if c.name == 'h2'
|
42
|
+
h2 += 1
|
61
43
|
next
|
62
|
-
elsif a != ?~ && a != ?/
|
63
|
-
if continue
|
64
|
-
moveset.moves.last << a
|
65
|
-
else
|
66
|
-
(moveset.moves ||= []) << [a]
|
67
|
-
end
|
68
|
-
continue = false
|
69
44
|
end
|
45
|
+
if c.name == 'ul'
|
46
|
+
ul += 1
|
47
|
+
next
|
48
|
+
end
|
49
|
+
break if ul >= 2
|
50
|
+
d << c.text if h2 == 1 && !c.text.strip.empty?
|
70
51
|
}
|
71
|
-
|
72
|
-
moveset.evs = s.xpath('.//td').last.text.strip
|
73
|
-
|
74
|
-
movesets[i] = moveset
|
75
|
-
i += 1
|
76
52
|
}
|
77
|
-
|
78
|
-
|
53
|
+
|
54
|
+
info = smogon.xpath('//table[@class="info"]/tr')[1].xpath('.//td')
|
55
|
+
move.type = info[0].text
|
56
|
+
move.power = info[1].text
|
57
|
+
move.accuracy = info[2].text
|
58
|
+
move.pp = info[3].text
|
59
|
+
move.priority = info[4].text
|
60
|
+
move.damage = info[5].text.strip
|
61
|
+
move.target = info[6].text.strip
|
62
|
+
return move
|
79
63
|
end
|
80
64
|
end
|
81
|
-
end
|
65
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright(C) 2013 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
|
+
class Movesetdex
|
22
|
+
def self.get(name, tier)
|
23
|
+
begin
|
24
|
+
url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/#{tier}"
|
25
|
+
|
26
|
+
smogon = Nokogiri::HTML(open(url))
|
27
|
+
rescue
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
movesets = []
|
32
|
+
|
33
|
+
smogon.xpath('//table[@class="info strategyheader"]').each { |s|
|
34
|
+
moveset = Moveset.new
|
35
|
+
|
36
|
+
moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
|
37
|
+
moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
|
38
|
+
moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
|
39
|
+
|
40
|
+
s.xpath('.//a').each { |a|
|
41
|
+
(moveset.item ||= []) << a.text if a['href'].include? '/items/'
|
42
|
+
(moveset.ability ||= []) << a.text if a['href'].include? '/abilities/'
|
43
|
+
(moveset.nature ||= []) << a.text if a['href'].include? '/natures/'
|
44
|
+
}
|
45
|
+
|
46
|
+
movesets << moveset
|
47
|
+
}
|
48
|
+
|
49
|
+
i = 0
|
50
|
+
smogon.xpath('//table[@class="info moveset"]').each { |s|
|
51
|
+
moveset = movesets[i]
|
52
|
+
|
53
|
+
continue = false
|
54
|
+
s.xpath('.//td')[0].text.each_line { |a|
|
55
|
+
a = a.gsub(/\n?/, '').strip
|
56
|
+
if a == ?~
|
57
|
+
continue = false
|
58
|
+
elsif a == ?/
|
59
|
+
continue = true
|
60
|
+
elsif a.empty?
|
61
|
+
next
|
62
|
+
elsif a != ?~ && a != ?/
|
63
|
+
if continue
|
64
|
+
moveset.moves.last << a
|
65
|
+
else
|
66
|
+
(moveset.moves ||= []) << [a]
|
67
|
+
end
|
68
|
+
continue = false
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
moveset.evs = s.xpath('.//td').last.text.strip
|
73
|
+
|
74
|
+
movesets[i] = moveset
|
75
|
+
i += 1
|
76
|
+
}
|
77
|
+
|
78
|
+
return movesets
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
#--
|
3
2
|
# Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
|
4
3
|
#
|
@@ -19,12 +18,15 @@
|
|
19
18
|
#++
|
20
19
|
|
21
20
|
module Smogon
|
22
|
-
class
|
23
|
-
attr_accessor :
|
21
|
+
class Move
|
22
|
+
attr_accessor :name, :_name, :description, :type, :power, :accuracy, :pp, :priority, :damage, :target
|
24
23
|
|
25
24
|
def to_s
|
26
|
-
"
|
25
|
+
"Name: #{name}\nDescription: #{description}\nType: #{type}\nPower: #{power}\nAccuracy: #{accuracy}\nPP: #{pp}\nPriority: #{priority}\nDamage: #{damage}\nTarget: #{target}"
|
27
26
|
end
|
28
27
|
|
28
|
+
def url
|
29
|
+
"http://www.smogon.com/bw/moves/#{_name}"
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/smogon/version.rb
CHANGED
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.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: API written in Ruby to get
|
27
|
+
description: API written in Ruby to get (poké|ability|move|moveset)dex from Smogon.
|
28
28
|
email: webmaster@giovannicapuano.net
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -32,10 +32,11 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- lib/smogon/abilitydex.rb
|
34
34
|
- lib/smogon/movedex.rb
|
35
|
-
- lib/smogon/
|
35
|
+
- lib/smogon/movesetdex.rb
|
36
36
|
- lib/smogon/pokedex.rb
|
37
37
|
- lib/smogon/pokemon.rb
|
38
38
|
- lib/smogon/types/ability.rb
|
39
|
+
- lib/smogon/types/move.rb
|
39
40
|
- lib/smogon/types/moveset.rb
|
40
41
|
- lib/smogon/types/pokemon.rb
|
41
42
|
- lib/smogon/version.rb
|