smogon 0.1

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWZlODFlOWI1OTRhZGJjOWZmZjc1YzllZWVhODU2OTQ2ZDNiNDY1Mw==
5
+ data.tar.gz: !binary |-
6
+ MmI4NjIwOWY5YTU5NmZiNWJjNDA3NjY1YmUxOThmM2FiN2ZiMTNkMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTNmMTUwYmMwMTBkNGQzNGU2MDA1MjZlNGVjMjQ4MjY4OTk3OWI2NTRkYTJk
10
+ YTNhMjRmNDkxZmJkMDBhNDlmN2VkNDA5ZjIwYTM5MTM5MTBmMzJlMjY4M2E3
11
+ MTMwZTRmZjJmZTYyMTRjNDQ0YmFlOTczNGFkYWZkOTA3ZWZkNWY=
12
+ data.tar.gz: !binary |-
13
+ MTM0ZDNiZDBmMjNlMjM2NWVjNTZlODM5ZGI0M2Y3MWI0OGIxZDljOGQ2MjFm
14
+ ZTQ1NWRhZWJjMzE5YjVmNmY5MzEzN2EyZDhlZTdhMjk3NzYzYjM3OTkwNTUz
15
+ M2Q5OTI5MWVjYzY3Y2U5MzA0MzBjYzdhN2MzNjEzMjc3MmFmYzY=
@@ -0,0 +1,29 @@
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
+ require 'open-uri'
21
+ require 'nokogiri'
22
+
23
+ require 'smogon/pokemon'
24
+ require 'smogon/pokedex'
25
+
26
+ require 'smogon/moveset'
27
+ require 'smogon/movedex'
28
+
29
+ require 'smogon/version'
@@ -0,0 +1,83 @@
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 Movedex
22
+
23
+ def self.get(name, tier)
24
+
25
+ begin
26
+ url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/#{tier}"
27
+
28
+ smogon = Nokogiri::HTML(open(url))
29
+ rescue
30
+ return nil
31
+ end
32
+
33
+ movesets = []
34
+
35
+ smogon.xpath('//table[@class="info strategyheader"]').each { |s|
36
+ moveset = Moveset.new
37
+
38
+ moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
39
+ moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
40
+ moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
41
+
42
+ s.xpath('.//a').each { |a|
43
+ (moveset.item ||= []) << a.text if a['href'].include? '/items/'
44
+ (moveset.ability ||= []) << a.text if a['href'].include? '/abilities/'
45
+ (moveset.nature ||= []) << a.text if a['href'].include? '/natures/'
46
+ }
47
+
48
+ movesets << moveset
49
+ }
50
+
51
+ i = 0
52
+ smogon.xpath('//table[@class="info moveset"]').each { |s|
53
+ moveset = movesets[i]
54
+
55
+ continue = false
56
+ s.xpath('.//td')[0].text.each_line { |a|
57
+ a = a.gsub(/\n?/, '').strip
58
+ if a == ?~
59
+ continue = false
60
+ elsif a == ?/
61
+ continue = true
62
+ elsif a.empty?
63
+ next
64
+ elsif a != ?~ && a != ?/
65
+ if continue
66
+ moveset.moves.last << a
67
+ else
68
+ (moveset.moves ||= []) << [a]
69
+ end
70
+ continue = false
71
+ end
72
+ }
73
+
74
+ moveset.evs = s.xpath('.//td').last.text.strip
75
+
76
+ movesets[i] = moveset
77
+ i += 1
78
+ }
79
+
80
+ return movesets
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,30 @@
1
+ #encoding: utf-8
2
+ #--
3
+ # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
4
+ #
5
+ # This file is part of Smogon-API.
6
+ #
7
+ # Smogon-API is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Smogon-API is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Smogon-API. If not, see <http://www.gnu.org/licenses/>.
19
+ #++
20
+
21
+ module Smogon
22
+ class Moveset
23
+ attr_accessor :pokemon, :name, :tier, :item, :ability, :nature, :moves, :evs
24
+
25
+ def to_s
26
+ "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}"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,59 @@
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 Pokedex
22
+
23
+ def self.get(name)
24
+ begin
25
+ url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}"
26
+
27
+ pokemon = Pokemon.new
28
+ smogon = Nokogiri::HTML(open(url))
29
+ rescue
30
+ return nil
31
+ end
32
+
33
+ pokemon.name = smogon.xpath('//td[@class="header"]/h1').last.text
34
+ pokemon._name = pokemon.name.downcase
35
+
36
+ smogon.xpath('//table[@class="info"]/tr/td/a')[0..-2].each { |type|
37
+ (pokemon.types ||= []) << type.text
38
+ }
39
+
40
+ pokemon.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
41
+
42
+ smogon.xpath('//td[@class="ability"]/dl/dt/a').each { |ability|
43
+ (pokemon.abilities ||= []) << ability.text
44
+ }
45
+
46
+ begin
47
+ (pokemon.abilities ||= []) << smogon.xpath('//td[@class="ability"]/dl/dt/em/a').first.text
48
+ rescue
49
+ # No dream world ability :(
50
+ end
51
+
52
+ smogon.xpath('//td[@class="bar"]').each { |base_stat|
53
+ (pokemon.base_stats ||= []) << base_stat.text.strip
54
+ }
55
+
56
+ return pokemon
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,28 @@
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 Pokemon
22
+ attr_accessor :name, :_name, :types, :tier, :abilities, :base_stats
23
+
24
+ def to_s
25
+ "Name: #{name}\nAbility: #{abilities.join(', ')}\nType: #{types.join(?/)}\nTier: #{tier}\nBase stats: #{base_stats.join(?/)}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
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
+ def self.version
22
+ '0.1'
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smogon
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Giovanni Capuano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: API written in Ruby to get Pokémon infos and movesets from Smogon.
28
+ email: webmaster@giovannicapuano.net
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/smogon/movedex.rb
34
+ - lib/smogon/moveset.rb
35
+ - lib/smogon/pokedex.rb
36
+ - lib/smogon/pokemon.rb
37
+ - lib/smogon/version.rb
38
+ - lib/smogon.rb
39
+ homepage: http://www.giovannicapuano.net
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.4
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Smogon API in Ruby.
62
+ test_files: []