botemon 0.3 → 0.3.2

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
- MTQ0ZGE1YzRlMjNlMTY1ZTRiMDA3ZTUzY2FhMmZmOGE2N2I0N2MxMQ==
4
+ ZjdjMjU4Y2VjNGRkMDlkY2Y2ZTNjNDIyNDNlMjRjZmJhODMxYzFjMg==
5
5
  data.tar.gz: !binary |-
6
- ZDk0ODJiNWJlOGNkNWZjZTk0YjU3NjFlZmQxMDkwMGNkNTM1OTA1Mg==
6
+ NmMzMTQyNzlhNWRlZjM5MTg0YTlhOWFlZTc4OWRmY2I5MTYwYjAwOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWY4NTY4NmJmNWE5NzU0NGVjODY0YmNhNzAzNDAxNWEzYmE1MzAzODRjNjI3
10
- YTljZmRlY2I0MGZlMTQ1MzEzZTRlOThjZTAwM2U1MmI1OGU5NTFlNjcxYzMw
11
- OWNjOTc0OTQwYWEzZGI2ZGQ5OWY2NjA0NGRkZjVlZDgwYjU2YTE=
9
+ YTA5YWE3MDg4YjA5YTM5YTZlZDc2YmVmMzI1MGI2MmZmMTBlMGExYTUzM2Zi
10
+ ZTExYTFiZmZhMjA2MDg5NDU2MDRhYmI5NWJiNDI2MGE0Zjc4NTNmNzc3Mjc1
11
+ MjQ2NWZkYzc4NmEwMWE0ODRmMTY0NzBhNWIwMTE2YTczOGZjZWI=
12
12
  data.tar.gz: !binary |-
13
- YjNjNjEwZTM5ODYzNzU3Y2E2M2QwNTU3MDdlODhmMDQ1ZDUzMTU4ODg1MTE4
14
- ZDdkNGY2NTQ1ZmE0OTRjYWRmMWFjZTQ3YjE0NmFlMmViMjVmYjU0ZTc3NTQ0
15
- ZThlM2M3ZGMwZjlmYThmZTA0YTEyMjE3OWNhYmIxNzQ0YWZmMzA=
13
+ YTY3NWIyNTFkM2M2M2IwOGMxMWYxMDIzNDhhNDhmYTJmNmQ4NTE5NGQ2Mjg2
14
+ OTkxN2Y5NmEzZWVmM2QwMTZhOTBhODdjYjQ5ODQwZWY2MTQzYzhiZWQzMTI5
15
+ NDgzOGQ2MGIwMzQ1MDA0OWU0OWRiNDRiNjY3YWE5MDZlMDFkM2I=
@@ -17,21 +17,20 @@
17
17
  # along with Botémon. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
 
20
- require 'cinch'
21
- require 'cinch/plugins/login'
22
-
23
20
  require 'open-uri'
24
21
  require 'nokogiri'
25
22
  require 'sanitize'
26
23
  require 'json'
27
24
 
25
+ require 'cinch'
26
+ require 'cinch/plugins/login'
27
+ require 'smogon'
28
+
28
29
  require 'botemon/string'
29
- require 'botemon/pokemon'
30
+ require 'botemon/smogon/pokemon'
31
+ require 'botemon/smogon/moveset'
30
32
  require 'botemon/storage'
31
33
  require 'botemon/pokedex'
32
-
33
- require 'botemon/moveset'
34
34
  require 'botemon/movedex'
35
35
 
36
-
37
36
  require 'botemon/version'
@@ -19,71 +19,15 @@
19
19
 
20
20
  class Movedex
21
21
  def self.id2name(id)
22
- begin
23
- return Nokogiri::HTML(open("http://pokemondb.net/pokedex/#{id}")).xpath('//div[@class="navbar"]/h1')[0].text
22
+ return begin
23
+ Nokogiri::HTML(open("http://pokemondb.net/pokedex/#{id}")).xpath('//div[@class="navbar"]/h1')[0].text
24
24
  rescue
25
- return nil
25
+ nil
26
26
  end
27
27
  end
28
28
 
29
29
  def self.get(name, tier)
30
30
  return nil if name == nil || tier == nil
31
-
32
- begin
33
- url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/#{tier}"
34
-
35
- smogon = Nokogiri::HTML(open(url))
36
- rescue
37
- return nil
38
- end
39
-
40
- movesets = []
41
-
42
- smogon.xpath('//table[@class="info strategyheader"]').each { |s|
43
- moveset = Moveset.new
44
-
45
- moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
46
- moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
47
- moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
48
-
49
- s.xpath('.//a').each { |a|
50
- (moveset.item ||= []) << a.text if a['href'].include? '/items/'
51
- (moveset.ability ||= []) << a.text if a['href'].include? '/abilities/'
52
- (moveset.nature ||= []) << a.text if a['href'].include? '/natures/'
53
- }
54
-
55
- movesets << moveset
56
- }
57
-
58
- i = 0
59
- smogon.xpath('//table[@class="info moveset"]').each { |s|
60
- moveset = movesets[i]
61
-
62
- continue = false
63
- s.xpath('.//td')[0].text.each_line { |a|
64
- a = a.gsub(/\n?/, '').strip
65
- if a == ?~
66
- continue = false
67
- elsif a == ?/
68
- continue = true
69
- elsif a.empty?
70
- next
71
- elsif a != ?~ && a != ?/
72
- if continue
73
- moveset.moves.last << a
74
- else
75
- (moveset.moves ||= []) << [a]
76
- end
77
- continue = false
78
- end
79
- }
80
-
81
- moveset.evs = s.xpath('.//td').last.text.strip
82
-
83
- movesets[i] = moveset
84
- i += 1
85
- }
86
-
87
- return movesets
31
+ return Smogon::Movedex.get name, tier
88
32
  end
89
33
  end
@@ -28,42 +28,14 @@ class Pokedex
28
28
 
29
29
  def self.get(name, storage)
30
30
  return nil if name == nil
31
- return storage.get(name) if storage.is_cached? name
32
31
 
33
- begin
34
- url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}"
35
-
36
- pokemon = Pokemon.new
37
- smogon = Nokogiri::HTML(open(url))
38
- rescue
39
- return nil
32
+ if storage.is_cached?(name)
33
+ return storage.get name
34
+ else
35
+ pokemon = Smogon::Pokedex.get name
36
+ storage.add pokemon
37
+ storage.save
38
+ return pokemon
40
39
  end
41
-
42
- pokemon.name = smogon.xpath('//td[@class="header"]/h1').last.text
43
- pokemon._name = pokemon.name.downcase
44
-
45
- smogon.xpath('//table[@class="info"]/tr/td/a')[0..-2].each { |type|
46
- (pokemon.types ||= []) << type.text
47
- }
48
-
49
- pokemon.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
50
-
51
- smogon.xpath('//td[@class="ability"]/dl/dt/a').each { |ability|
52
- (pokemon.abilities ||= []) << ability.text
53
- }
54
-
55
- begin
56
- (pokemon.abilities ||= []) << smogon.xpath('//td[@class="ability"]/dl/dt/em/a').first.text
57
- rescue
58
- # No dream world ability :(
59
- end
60
-
61
- smogon.xpath('//td[@class="bar"]').each { |base_stat|
62
- (pokemon.base_stats ||= []) << base_stat.text.strip
63
- }
64
-
65
- storage.add pokemon
66
- storage.save
67
- return pokemon
68
40
  end
69
41
  end
@@ -1,4 +1,3 @@
1
- #encoding: utf-8
2
1
  #--
3
2
  # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
4
3
  #
@@ -18,11 +17,13 @@
18
17
  # along with Botémon. If not, see <http://www.gnu.org/licenses/>.
19
18
  #++
20
19
 
21
- class Moveset
22
- attr_accessor :pokemon, :name, :tier, :item, :ability, :nature, :moves, :evs
23
-
24
- def to_s
25
- "Item: #{item.join(' / ')}\nAbility: #{ability.join(' / ')}\nNature: #{nature.join(' / ')}\nMoves: #{''.tap { |s| moves.each { |move| s << move.join(' / ') + ', '}}[0..-3]}\nEVs: #{evs}"
20
+ module Smogon
21
+ class Moveset
22
+ attr_accessor :pokemon, :name, :tier, :item, :ability, :nature, :moves, :evs
23
+
24
+ def to_s
25
+ "Item: #{item.join(' / ')}\nAbility: #{ability.join(' / ')}\nNature: #{nature.join(' / ')}\nMoves: #{''.tap { |s| moves.each { |move| s << move.join(' / ') + ', '}}[0..-3]}\nEVs: #{evs}"
26
+ end
27
+
26
28
  end
27
-
28
29
  end
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # This file is part of Botémon.
5
+ #
6
+ # Botémon 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
+ # Botémon 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 Botémon. 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
+
28
+ def clues
29
+ "Ability: #{abilities.join(', ')}\nType: #{types.join(?/)}\nTier: #{tier}\nBase stats: #{base_stats.join(?/)}"
30
+ end
31
+
32
+ def self.to_pokemon(ary)
33
+ return Pokemon.new.tap { |pokemon|
34
+ pokemon.name = ary['name']
35
+ pokemon._name = ary['_name']
36
+ pokemon.types = ary['types']
37
+ pokemon.tier = ary['tier']
38
+ pokemon.abilities = ary['abilities']
39
+ pokemon.base_stats = ary['base_stats']
40
+ }
41
+ end
42
+
43
+ def to_ary
44
+ { 'name' => name,
45
+ '_name' => _name,
46
+ 'types' => types,
47
+ 'tier' => tier,
48
+ 'abilities' => abilities,
49
+ 'base_stats' => base_stats
50
+ }
51
+ end
52
+ end
53
+ end
@@ -23,7 +23,7 @@ class Storage
23
23
  def initialize(file)
24
24
  @file = file
25
25
  @db = [].tap { |db|
26
- (File.exists?(file) ? JSON.load(File.read(file)) : []).each { |p| db << Pokemon.to_pokemon(p) }
26
+ (File.exists?(file) ? JSON.load(File.read(file)) : []).each { |p| db << Smogon::Pokemon.to_pokemon(p) }
27
27
  }
28
28
  end
29
29
 
@@ -1,25 +1,24 @@
1
- #encoding: utf-8
2
1
  #--
3
2
  # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
4
3
  #
5
- # This file is part of BOTémon.
4
+ # This file is part of Botémon.
6
5
  #
7
- # BOTémon is free software: you can redistribute it and/or modify
6
+ # Botémon is free software: you can redistribute it and/or modify
8
7
  # it under the terms of the GNU General Public License as published by
9
8
  # the Free Software Foundation, either version 3 of the License, or
10
9
  # (at your option) any later version.
11
10
  #
12
- # BOTémon is distributed in the hope that it will be useful,
11
+ # Botémon is distributed in the hope that it will be useful,
13
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
14
  # GNU General Public License for more details.
16
15
  #
17
16
  # You should have received a copy of the GNU General Public License
18
- # along with BOTémon. If not, see <http://www.gnu.org/licenses/>.
17
+ # along with Botémon. If not, see <http://www.gnu.org/licenses/>.
19
18
  #++
20
19
 
21
20
  module Botemon
22
21
  def self.version
23
- '0.3'
22
+ '0.3.2'
24
23
  end
25
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botemon
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: cinch
14
+ name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ! '>='
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: cinch-login
28
+ name: sanitize
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ! '>='
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: nokogiri
42
+ name: cinch
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ! '>='
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: sanitize
56
+ name: cinch-login
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: smogon
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ! '>='
@@ -74,9 +88,9 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - lib/botemon/movedex.rb
77
- - lib/botemon/moveset.rb
78
91
  - lib/botemon/pokedex.rb
79
- - lib/botemon/pokemon.rb
92
+ - lib/botemon/smogon/moveset.rb
93
+ - lib/botemon/smogon/pokemon.rb
80
94
  - lib/botemon/storage.rb
81
95
  - lib/botemon/string.rb
82
96
  - lib/botemon/version.rb
@@ -1,51 +0,0 @@
1
- #--
2
- # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
3
- #
4
- # This file is part of Botémon.
5
- #
6
- # Botémon 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
- # Botémon 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 Botémon. If not, see <http://www.gnu.org/licenses/>.
18
- #++
19
-
20
- class Pokemon
21
- attr_accessor :name, :_name, :types, :tier, :abilities, :base_stats
22
-
23
- def to_s
24
- "Name: #{name}\nAbility: #{abilities.join(', ')}\nType: #{types.join(?/)}\nTier: #{tier}\nBase stats: #{base_stats.join(?/)}"
25
- end
26
-
27
- def clues
28
- "Ability: #{abilities.join(', ')}\nType: #{types.join(?/)}\nTier: #{tier}\nBase stats: #{base_stats.join(?/)}"
29
- end
30
-
31
- def self.to_pokemon(ary)
32
- pokemon = Pokemon.new
33
- pokemon.name = ary['name']
34
- pokemon._name = ary['_name']
35
- pokemon.types = ary['types']
36
- pokemon.tier = ary['tier']
37
- pokemon.abilities = ary['abilities']
38
- pokemon.base_stats = ary['base_stats']
39
- return pokemon
40
- end
41
-
42
- def to_ary
43
- { 'name' => name,
44
- '_name' => _name,
45
- 'types' => types,
46
- 'tier' => tier,
47
- 'abilities' => abilities,
48
- 'base_stats' => base_stats
49
- }
50
- end
51
- end