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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmQ0ZDY0NjQ5MjA3NzJiMzlhZmQ1Nzc4MzE5Yjc2MmI1ZTVjOWFiNg==
4
+ MWFhYzlhYmU0YTU4OGM3OTAxMWNlODg3MTFjZDk2ZTZmNTJjNDA1NQ==
5
5
  data.tar.gz: !binary |-
6
- ZDA1OTkwNzFlZDM4MWZkZDYyMmU0MThmMmM0Zjg2ODI3MTFiOGJlYQ==
6
+ MmRlMzZmOTA3YjY4MTJkNzdjNmEwOTAxNTBjMjBjZjE1NjJlNzIwNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Njk3YjA0Y2UwY2E0MjYzZDk4Nzc4OGQ0OWJkMjYwYWI3OTllODMyMDhhMTU3
10
- M2YzOGE1MzUwN2Q3MTFmMWQzZjA4ZjFjNmU2YzMwZGE1OGU0NjNjZGFmMzRi
11
- M2U5YzQ3OTgwMTA3MDllNGI3OTY3MzVmYTU2NDU1NTZjZGFiNjQ=
9
+ YWU0MDJiMjY1ZTFjOTJhN2FiNGE1MzA5OTQ2ZjI3NmVmMzFhMWY4YzI4ZmMx
10
+ MzNjZTlhYTlmZTkwZGNmZDM0ZGUxZDAzMmI5MjAwYmNhNmExZDlhZTU2ZGRj
11
+ NTIyYTBlOWVlYWQ0NTAyZGQ0NWU2MzNmNmFjZjNiOTU5NjcxYWM=
12
12
  data.tar.gz: !binary |-
13
- MWM3NmQ0MWY4ZDQ2YmViNmIxZjY4MWIzOWNhZjUxMTFiMjJmMTk1YmY4Yzk3
14
- NTg4NzhlMTRmMTlmZTJmNTVjNzE4MTZlNzEyMGI0YzQ2MjE0YzE5MWRkNDMx
15
- MGExMmU0Y2E0YWFiNGYyYWQxMWRhNDViYWE1YWFhNTZkZGQ4NDQ=
13
+ MzllMjg4MGEzNmE5Mjg5NzA3ZDYwZWIxNWUxMjMyNjMzYjJhYzM0NGQwNTA4
14
+ ZTgyMjg4NzkwNGVkMjJiZTk5YzU0Y2QzMzgxMjNmMzBmZDE3NGEyMDk4OThi
15
+ NDU0ZTNiNmI2YzFhMGVjZTFkYjVjNDY5NGE0NjFkY2E2ZmFhMDI=
@@ -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'
@@ -21,7 +21,7 @@ module Smogon
21
21
  class Abilitydex
22
22
  def self.get(name)
23
23
  begin
24
- name = name.downcase.gsub!(/\s/, ?_)
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
@@ -19,63 +19,47 @@
19
19
 
20
20
  module Smogon
21
21
  class Movedex
22
- def self.get(name, tier)
22
+ def self.get(name)
23
23
  begin
24
- url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/#{tier}"
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
- movesets = []
32
+ move = Move.new
32
33
 
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
- }
34
+ move.name = smogon.xpath('//div[@id="content_wrapper"]/h1').first.text
35
+ move._name = name
48
36
 
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?
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
- return movesets
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 Moveset
23
- attr_accessor :pokemon, :name, :tier, :item, :ability, :nature, :moves, :evs
21
+ class Move
22
+ attr_accessor :name, :_name, :description, :type, :power, :accuracy, :pp, :priority, :damage, :target
24
23
 
25
24
  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}"
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
@@ -19,6 +19,6 @@
19
19
 
20
20
  module Smogon
21
21
  def self.version
22
- '0.2.1'
22
+ '0.3'
23
23
  end
24
- end
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.2.1
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 00:00:00.000000000 Z
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 Pokémon infos and movesets from Smogon.
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/moveset.rb
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