smogon 0.3.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smogon.rb +2 -0
- data/lib/smogon/itemdex.rb +58 -0
- data/lib/smogon/types/item.rb +32 -0
- data/lib/smogon/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bf05ec9749d9c9766d843099a44445197e4b840
|
4
|
+
data.tar.gz: c7e0078c7a3fb4ae19eb7b562bca7e9d477f275c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd9640d7219e6c5d184bf6de991c4c7a1ba19e5c1165d7bb35237ae9bf81d9c2beb545e7d32c5b5cff563bb84f2b803216a8cadb03db27f4f03a49e8ce52af3c
|
7
|
+
data.tar.gz: a6b6d35fa7dc5faa8adcb3498098087d62e8f6bf8de82b5a3ed174c3079e9a3d853c2e11d9f9c3c3b3f9b1299b693d74c08df3e83d8140770d517c6f0217e873
|
data/lib/smogon.rb
CHANGED
@@ -22,11 +22,13 @@ require 'nokogiri'
|
|
22
22
|
|
23
23
|
require 'smogon/types/pokemon'
|
24
24
|
require 'smogon/types/ability'
|
25
|
+
require 'smogon/types/item'
|
25
26
|
require 'smogon/types/move'
|
26
27
|
require 'smogon/types/moveset'
|
27
28
|
|
28
29
|
require 'smogon/pokedex'
|
29
30
|
require 'smogon/abilitydex'
|
31
|
+
require 'smogon/itemdex'
|
30
32
|
require 'smogon/movedex'
|
31
33
|
require 'smogon/movesetdex'
|
32
34
|
|
@@ -0,0 +1,58 @@
|
|
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 Itemdex
|
22
|
+
def self.get(name)
|
23
|
+
begin
|
24
|
+
name = name.downcase.gsub /\s/, ?_
|
25
|
+
url = URI::encode "http://www.smogon.com/bw/items/#{name}"
|
26
|
+
|
27
|
+
smogon = Nokogiri::HTML(open(url))
|
28
|
+
rescue
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
item = Item.new
|
33
|
+
|
34
|
+
s = smogon.xpath('//div[@id="content_wrapper"]')[0]
|
35
|
+
item.name = s.xpath('.//h1').first.text
|
36
|
+
item._name = name
|
37
|
+
|
38
|
+
item.description = ''.tap { |d|
|
39
|
+
h2 = 0
|
40
|
+
ul = 0
|
41
|
+
s.children.each { |c|
|
42
|
+
if c.name == 'h2'
|
43
|
+
h2 += 1
|
44
|
+
next
|
45
|
+
end
|
46
|
+
if c.name == 'ul'
|
47
|
+
ul += 1
|
48
|
+
next
|
49
|
+
end
|
50
|
+
break if ul >= 2
|
51
|
+
d << c.text if h2 == 1 && !c.text.strip.empty?
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
return item
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 Item
|
22
|
+
attr_accessor :name, :_name, :description
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"Name: #{name}\nDescription: #{description}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def url
|
29
|
+
"http://www.smogon.com/bw/items/#{_name}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/smogon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smogon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
@@ -31,10 +31,12 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/smogon/abilitydex.rb
|
34
|
+
- lib/smogon/itemdex.rb
|
34
35
|
- lib/smogon/movedex.rb
|
35
36
|
- lib/smogon/movesetdex.rb
|
36
37
|
- lib/smogon/pokedex.rb
|
37
38
|
- lib/smogon/types/ability.rb
|
39
|
+
- lib/smogon/types/item.rb
|
38
40
|
- lib/smogon/types/move.rb
|
39
41
|
- lib/smogon/types/moveset.rb
|
40
42
|
- lib/smogon/types/pokemon.rb
|