smogon 0.4.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smogon/abilitydex.rb +23 -26
- data/lib/smogon/itemdex.rb +23 -26
- data/lib/smogon/movedex.rb +36 -38
- data/lib/smogon/movesetdex.rb +50 -53
- data/lib/smogon/pokedex.rb +30 -31
- data/lib/smogon/types/ability.rb +2 -2
- data/lib/smogon/types/moveset.rb +0 -1
- data/lib/smogon/types/pokemon.rb +4 -4
- data/lib/smogon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd0731542bdbe9f388f16b573287396022ec427
|
4
|
+
data.tar.gz: 0c7a8cf702effe4365ec2fda7efbc826d2785a17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3ccb31e36294882007c0e733fe4b4e3bf2bab717b3e4371a70d9b27282c062f006ddaaccfa9fdbdf47903e351eb70ee3aefeb441e1674e580d77d70e76fc9c9
|
7
|
+
data.tar.gz: 7c9a7cc677e1a3f3656e24897806c48f22ac75dc7f9f0bd2d34f0a008a24669559ab8193b6841c3e7ba164a8246e546f4af7b3cc56ae027ce3574e8df203c8bb
|
data/lib/smogon/abilitydex.rb
CHANGED
@@ -21,38 +21,35 @@ module Smogon
|
|
21
21
|
class Abilitydex
|
22
22
|
def self.get(name)
|
23
23
|
begin
|
24
|
-
name
|
25
|
-
url
|
26
|
-
|
27
|
-
smogon = Nokogiri::HTML(open(url))
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
|
+
url = URI::encode "http://www.smogon.com/bw/abilities/#{name}"
|
26
|
+
smogon = Nokogiri::HTML open(url)
|
28
27
|
rescue
|
29
28
|
return nil
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
31
|
+
Ability.new.tap { |ability|
|
32
|
+
s = smogon.xpath('//div[@id="content_wrapper"]')[0]
|
33
|
+
ability.name = s.xpath('.//h1').first.text
|
34
|
+
ability._name = name
|
35
|
+
|
36
|
+
ability.description = ''.tap { |d|
|
37
|
+
h2 = 0
|
38
|
+
ul = 0
|
39
|
+
s.children.each { |c|
|
40
|
+
if c.name == 'h2'
|
41
|
+
h2 += 1
|
42
|
+
next
|
43
|
+
end
|
44
|
+
if c.name == 'ul'
|
45
|
+
ul += 1
|
46
|
+
next
|
47
|
+
end
|
48
|
+
break if ul >= 2
|
49
|
+
d << c.text if h2 == 1 && !c.text.strip.empty?
|
50
|
+
}
|
52
51
|
}
|
53
52
|
}
|
54
|
-
|
55
|
-
return ability
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
data/lib/smogon/itemdex.rb
CHANGED
@@ -21,38 +21,35 @@ module Smogon
|
|
21
21
|
class Itemdex
|
22
22
|
def self.get(name)
|
23
23
|
begin
|
24
|
-
name
|
25
|
-
url
|
26
|
-
|
27
|
-
smogon = Nokogiri::HTML(open(url))
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
|
+
url = URI::encode "http://www.smogon.com/bw/items/#{name}"
|
26
|
+
smogon = Nokogiri::HTML open(url)
|
28
27
|
rescue
|
29
28
|
return nil
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
31
|
+
Item.new.tap { |item|
|
32
|
+
s = smogon.xpath('//div[@id="content_wrapper"]')[0]
|
33
|
+
item.name = s.xpath('.//h1').first.text
|
34
|
+
item._name = name
|
35
|
+
|
36
|
+
item.description = ''.tap { |d|
|
37
|
+
h2 = 0
|
38
|
+
ul = 0
|
39
|
+
s.children.each { |c|
|
40
|
+
if c.name == 'h2'
|
41
|
+
h2 += 1
|
42
|
+
next
|
43
|
+
end
|
44
|
+
if c.name == 'ul'
|
45
|
+
ul += 1
|
46
|
+
next
|
47
|
+
end
|
48
|
+
break if ul >= 2
|
49
|
+
d << c.text if h2 == 1 && !c.text.strip.empty?
|
50
|
+
}
|
52
51
|
}
|
53
52
|
}
|
54
|
-
|
55
|
-
return item
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
data/lib/smogon/movedex.rb
CHANGED
@@ -21,50 +21,48 @@ module Smogon
|
|
21
21
|
class Movedex
|
22
22
|
def self.get(name)
|
23
23
|
begin
|
24
|
-
name
|
25
|
-
url
|
26
|
-
|
27
|
-
smogon = Nokogiri::HTML(open(url))
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
|
+
url = URI::encode "http://www.smogon.com/bw/moves/#{name}"
|
26
|
+
smogon = Nokogiri::HTML open(url)
|
28
27
|
rescue
|
29
28
|
return nil
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
Move.new.tap { |move|
|
32
|
+
move.name = smogon.xpath('//div[@id="content_wrapper"]/h1').first.text
|
33
|
+
move._name = name
|
34
|
+
|
35
|
+
move.description = ''.tap { |d|
|
36
|
+
h2 = 0
|
37
|
+
ul = 0
|
38
|
+
dl = 0
|
39
|
+
smogon.xpath('//div[@id="content_wrapper"]').children.each { |c|
|
40
|
+
if c.name == 'h2'
|
41
|
+
h2 += 1
|
42
|
+
next
|
43
|
+
end
|
44
|
+
if c.name == 'ul'
|
45
|
+
ul += 1
|
46
|
+
next
|
47
|
+
end
|
48
|
+
if c.name == 'dl'
|
49
|
+
dl += 1
|
50
|
+
next
|
51
|
+
end
|
52
|
+
break if ul >= 2 || dl >= 2
|
53
|
+
d << c.text if h2 == 1 && !c.text.strip.empty?
|
54
|
+
}
|
56
55
|
}
|
56
|
+
|
57
|
+
info = smogon.xpath('//table[@class="info"]/tr')[1].xpath('.//td')
|
58
|
+
move.type = info[0].text
|
59
|
+
move.power = info[1].text
|
60
|
+
move.accuracy = info[2].text
|
61
|
+
move.pp = info[3].text
|
62
|
+
move.priority = info[4].text
|
63
|
+
move.damage = info[5].text.strip
|
64
|
+
move.target = info[6].text.strip
|
57
65
|
}
|
58
|
-
|
59
|
-
info = smogon.xpath('//table[@class="info"]/tr')[1].xpath('.//td')
|
60
|
-
move.type = info[0].text
|
61
|
-
move.power = info[1].text
|
62
|
-
move.accuracy = info[2].text
|
63
|
-
move.pp = info[3].text
|
64
|
-
move.priority = info[4].text
|
65
|
-
move.damage = info[5].text.strip
|
66
|
-
move.target = info[6].text.strip
|
67
|
-
return move
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
data/lib/smogon/movesetdex.rb
CHANGED
@@ -21,68 +21,65 @@ module Smogon
|
|
21
21
|
class Movesetdex
|
22
22
|
def self.get(name, tier, metagame)
|
23
23
|
begin
|
24
|
-
url
|
25
|
-
|
24
|
+
url = URI::encode "http://www.smogon.com/#{metagame}/pokemon/#{name}/#{tier}"
|
26
25
|
smogon = Nokogiri::HTML(open(url))
|
27
26
|
rescue
|
28
27
|
return nil
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
movesets << moveset
|
53
|
-
}
|
54
|
-
|
55
|
-
i = 0
|
56
|
-
xpath = metagame == 'rb' ? '//td[@class="rbymoves"]' : '//table[@class="info moveset"]'
|
57
|
-
smogon.xpath(xpath).each { |s|
|
58
|
-
moveset = movesets[i]
|
59
|
-
|
60
|
-
continue = false
|
61
|
-
(metagame == 'rb' ? s : s.xpath('.//td')[0]).text.each_line { |a|
|
62
|
-
a = a.gsub(/\n?/, '').strip
|
63
|
-
if a == ?~
|
64
|
-
continue = false
|
65
|
-
elsif a == ?/
|
66
|
-
continue = true
|
67
|
-
elsif a.empty?
|
68
|
-
next
|
69
|
-
elsif a != ?~ && a != ?/
|
70
|
-
if continue
|
71
|
-
moveset.moves.last << a
|
72
|
-
else
|
73
|
-
moveset.moves << [a]
|
74
|
-
end
|
75
|
-
continue = false
|
30
|
+
[].tap { |movesets|
|
31
|
+
smogon.xpath('//table[@class="info strategyheader"]').each { |s|
|
32
|
+
moveset = Moveset.new
|
33
|
+
|
34
|
+
moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
|
35
|
+
moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
|
36
|
+
moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
|
37
|
+
|
38
|
+
if metagame == 'gs'
|
39
|
+
s.xpath('.//a').each { |a|
|
40
|
+
moveset.item << a.text if a['href'].include? '/items/'
|
41
|
+
}
|
42
|
+
elsif metagame != 'rb'
|
43
|
+
s.xpath('.//a').each { |a|
|
44
|
+
moveset.item << a.text if a['href'].include? '/items/'
|
45
|
+
moveset.ability << a.text if a['href'].include? '/abilities/'
|
46
|
+
moveset.nature << a.text if a['href'].include? '/natures/'
|
47
|
+
}
|
76
48
|
end
|
49
|
+
|
50
|
+
movesets << moveset
|
77
51
|
}
|
78
52
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
53
|
+
i = 0
|
54
|
+
xpath = metagame == 'rb' ? '//td[@class="rbymoves"]' : '//table[@class="info moveset"]'
|
55
|
+
smogon.xpath(xpath).each { |s|
|
56
|
+
moveset = movesets[i]
|
57
|
+
|
58
|
+
continue = false
|
59
|
+
(metagame == 'rb' ? s : s.xpath('.//td')[0]).text.each_line { |a|
|
60
|
+
a = a.gsub(/\n?/, '').strip
|
61
|
+
if a == ?~
|
62
|
+
continue = false
|
63
|
+
elsif a == ?/
|
64
|
+
continue = true
|
65
|
+
elsif a.empty?
|
66
|
+
next
|
67
|
+
elsif a != ?~ && a != ?/
|
68
|
+
if continue
|
69
|
+
moveset.moves.last << a
|
70
|
+
else
|
71
|
+
moveset.moves << [a]
|
72
|
+
end
|
73
|
+
continue = false
|
74
|
+
end
|
75
|
+
}
|
76
|
+
|
77
|
+
moveset.evs = s.xpath('.//td').last.text.strip if metagame != 'rb' && metagame != 'gs'
|
78
|
+
|
79
|
+
movesets[i] = moveset
|
80
|
+
i += 1
|
81
|
+
}
|
83
82
|
}
|
84
|
-
|
85
|
-
return movesets
|
86
83
|
end
|
87
84
|
end
|
88
85
|
end
|
data/lib/smogon/pokedex.rb
CHANGED
@@ -24,41 +24,40 @@ module Smogon
|
|
24
24
|
url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}"
|
25
25
|
moves_url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/moves"
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
moves = Nokogiri::HTML open(moves_url)
|
27
|
+
smogon = Nokogiri::HTML open url
|
28
|
+
moves = Nokogiri::HTML open moves_url
|
30
29
|
rescue
|
31
30
|
return nil
|
32
31
|
end
|
33
|
-
|
34
|
-
pokemon.name = smogon.xpath('//td[@class="header"]/h1').last.text
|
35
|
-
pokemon._name = pokemon.name.downcase
|
36
|
-
|
37
|
-
smogon.xpath('//table[@class="info"]/tr/td/a')[0..-2].each { |type|
|
38
|
-
(pokemon.types ||= []) << type.text
|
39
|
-
}
|
40
|
-
|
41
|
-
pokemon.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
|
42
|
-
|
43
|
-
smogon.xpath('//td[@class="ability"]/dl/dt/a').each { |ability|
|
44
|
-
(pokemon.abilities ||= []) << ability.text
|
45
|
-
}
|
46
|
-
|
47
|
-
begin
|
48
|
-
(pokemon.abilities ||= []) << smogon.xpath('//td[@class="ability"]/dl/dt/em/a').first.text
|
49
|
-
rescue
|
50
|
-
# No dream world abilities :(
|
51
|
-
end
|
52
|
-
|
53
|
-
smogon.xpath('//td[@class="bar"]').each { |base_stat|
|
54
|
-
(pokemon.base_stats ||= []) << base_stat.text.strip
|
55
|
-
}
|
56
|
-
|
57
|
-
moves.xpath('//table[starts-with(@id, "move_list")]/tbody/tr').each { |tr|
|
58
|
-
(pokemon.moves ||= []) << tr.xpath('.//td')[0].text.strip
|
59
|
-
}
|
60
32
|
|
61
|
-
|
33
|
+
Pokemon.new.tap { |pokemon|
|
34
|
+
pokemon.name = smogon.xpath('//td[@class="header"]/h1').last.text
|
35
|
+
pokemon._name = pokemon.name.downcase
|
36
|
+
|
37
|
+
smogon.xpath('//table[@class="info"]/tr/td/a')[0..-2].each { |type|
|
38
|
+
(pokemon.types ||= []) << type.text
|
39
|
+
}
|
40
|
+
|
41
|
+
pokemon.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
|
42
|
+
|
43
|
+
smogon.xpath('//td[@class="ability"]/dl/dt/a').each { |ability|
|
44
|
+
(pokemon.abilities ||= []) << ability.text
|
45
|
+
}
|
46
|
+
|
47
|
+
begin
|
48
|
+
(pokemon.abilities ||= []) << smogon.xpath('//td[@class="ability"]/dl/dt/em/a').first.text
|
49
|
+
rescue
|
50
|
+
# No dream world abilities :(
|
51
|
+
end
|
52
|
+
|
53
|
+
smogon.xpath('//td[@class="bar"]').each { |base_stat|
|
54
|
+
(pokemon.base_stats ||= []) << base_stat.text.strip
|
55
|
+
}
|
56
|
+
|
57
|
+
moves.xpath('//table[starts-with(@id, "move_list")]/tbody/tr').each { |tr|
|
58
|
+
(pokemon.moves ||= []) << tr.xpath('.//td')[0].text.strip
|
59
|
+
}
|
60
|
+
}
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
data/lib/smogon/types/ability.rb
CHANGED
@@ -22,11 +22,11 @@ module Smogon
|
|
22
22
|
attr_accessor :name, :_name, :description
|
23
23
|
|
24
24
|
def to_s
|
25
|
-
"Name: #{name}\nDescription: #{description}"
|
25
|
+
"Name: #{@name}\nDescription: #{@description}"
|
26
26
|
end
|
27
27
|
|
28
28
|
def url
|
29
|
-
"http://www.smogon.com/bw/abilities/#{_name}"
|
29
|
+
"http://www.smogon.com/bw/abilities/#{@_name}"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/smogon/types/moveset.rb
CHANGED
@@ -32,6 +32,5 @@ module Smogon
|
|
32
32
|
def to_s
|
33
33
|
"Pokémon: #{pokemon}\nSet: #{name}\nItem: #{item.join(' / ')}\nAbility: #{ability.join(' / ')}\nNature: #{nature.join(' / ')}\nMoves: #{''.tap { |s| moves.each { |move| s << move.join(' / ') + ', '}}[0..-3]}\nEVs: #{evs}"
|
34
34
|
end
|
35
|
-
|
36
35
|
end
|
37
36
|
end
|
data/lib/smogon/types/pokemon.rb
CHANGED
@@ -22,18 +22,18 @@ module Smogon
|
|
22
22
|
attr_accessor :name, :_name, :types, :tier, :abilities, :base_stats, :moves
|
23
23
|
|
24
24
|
def to_s
|
25
|
-
"Name: #{name}\nAbility: #{abilities.join(', ')}\nType: #{types.join(?/)}\nTier: #{tier}\nBase stats: #{base_stats.join(?/)}\nMoves: #{moves.join(', ')}"
|
25
|
+
"Name: #{@name}\nAbility: #{@abilities.join(', ')}\nType: #{@types.join(?/)}\nTier: #{@tier}\nBase stats: #{@base_stats.join(?/)}\nMoves: #{@moves.join(', ')}"
|
26
26
|
end
|
27
27
|
|
28
28
|
def url
|
29
|
-
"http://www.smogon.com/bw/pokemon/#{_name}"
|
29
|
+
"http://www.smogon.com/bw/pokemon/#{@_name}"
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.id2name(id)
|
33
33
|
begin
|
34
|
-
|
34
|
+
Nokogiri::HTML(open("http://www.marriland.com/pokedex/#{id}")).xpath('//div[@class="overview"]/h2')[0].text
|
35
35
|
rescue
|
36
|
-
|
36
|
+
nil
|
37
37
|
end
|
38
38
|
end
|
39
39
|
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.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|