ariejan-warcraft_armory 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +4 -0
- data/README.textile +7 -4
- data/lib/warcraft_armory.rb +35 -26
- data/test/warcraft_armory_test.rb +3 -2
- metadata +1 -1
data/Changelog
CHANGED
data/README.textile
CHANGED
@@ -22,11 +22,14 @@ h2. Download and installation
|
|
22
22
|
|
23
23
|
Simply install the RubyGem and require it in your project. If you're on rails, require it in your config/environment.rb.
|
24
24
|
|
25
|
-
<pre>gem install ariejan-
|
25
|
+
<pre>gem install ariejan-warcraft_armory --source http://gems.github.com</pre>
|
26
26
|
|
27
27
|
And require it when you need it:
|
28
28
|
|
29
|
-
<pre><code>
|
29
|
+
<pre><code>
|
30
|
+
require 'rubygems'
|
31
|
+
require 'warcraft_armory'
|
32
|
+
</code></pre>
|
30
33
|
|
31
34
|
Add the following to your environment.rb if you want to use Rails 2.1's dependency manager (which is highly recommended):
|
32
35
|
|
@@ -36,9 +39,9 @@ Add the following to your environment.rb if you want to use Rails 2.1's dependen
|
|
36
39
|
|
37
40
|
h2. Usage
|
38
41
|
|
39
|
-
<pre><code>character =
|
42
|
+
<pre><code>character = Warcraft::Amory.find(:eu, 'Aszune', 'Adries')</code></pre>
|
40
43
|
|
41
|
-
This will either return a
|
44
|
+
This will either return a Warcraft::Character object or nil when not character information was found.
|
42
45
|
|
43
46
|
h2. More Information
|
44
47
|
|
data/lib/warcraft_armory.rb
CHANGED
@@ -1,34 +1,43 @@
|
|
1
1
|
require 'hpricot'
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class WarcraftArmory
|
9
|
-
# Find a WoW character
|
10
|
-
#
|
11
|
-
# +location+ defines the server location, valid (tested) options are :eu or :us
|
12
|
-
# +realm+ the realm where your character is. E.g. "Aszune"
|
13
|
-
# +character_name+ the name of your character. E.g. "Adries"
|
14
|
-
def self.find(location, realm, character_name)
|
15
|
-
self.parse_html(Hpricot(open("http://#{location.to_s}.wowarmory.com/character-sheet.xml?r=#{realm}&n=#{character_name}")))
|
4
|
+
module Warcraft
|
5
|
+
class Character
|
6
|
+
attr_accessor :name, :level, :guild, :race, :class_name, :armory_url
|
16
7
|
end
|
8
|
+
|
9
|
+
class Armory
|
10
|
+
# Find a WoW character
|
11
|
+
#
|
12
|
+
# +location+ defines the server location, valid (tested) options are :eu or :us
|
13
|
+
# +realm+ the realm where your character is. E.g. "Aszune"
|
14
|
+
# +character_name+ the name of your character. E.g. "Adries"
|
15
|
+
def self.find(location, realm, character_name)
|
16
|
+
self.parse_html("http://#{location.to_s}.wowarmory.com/character-sheet.xml?r=#{realm}&n=#{character_name}")
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
+
protected
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def self.process(url)
|
22
|
+
html = Hpricot(open(url))
|
23
|
+
parse_html(html, url)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse_html(html, url)
|
27
|
+
char = Warcraft::Character.new
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
details = (html/"div.character-outer").inner_text.strip.split("\n")
|
30
|
+
small_details = details[4].split('?')
|
31
|
+
|
32
|
+
char.armory_url = url
|
33
|
+
char.name = details[0]
|
34
|
+
char.guild = details[2]
|
35
|
+
char.level = small_details[1]
|
36
|
+
char.race = small_details[2]
|
37
|
+
char.class_name = small_details[3]
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
end
|
39
|
+
char
|
40
|
+
end
|
41
|
+
end # class Armory
|
42
|
+
|
43
|
+
end # module Warcraft
|
@@ -24,8 +24,9 @@ class WarcraftArmoryTest < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_character_loading
|
27
|
-
character =
|
27
|
+
character = Warcraft::Armory.parse_html(@html, "http://armory_url")
|
28
28
|
|
29
|
+
assert_equal 'http://armory_url', character.armory_url
|
29
30
|
assert_equal 'Adries', character.name
|
30
31
|
assert_equal '13', character.level
|
31
32
|
assert_equal 'Human', character.race
|
@@ -33,6 +34,6 @@ class WarcraftArmoryTest < Test::Unit::TestCase
|
|
33
34
|
|
34
35
|
assert_equal 'The Justice League', character.guild
|
35
36
|
|
36
|
-
assert_equal
|
37
|
+
assert_equal Warcraft::Character, character.class
|
37
38
|
end
|
38
39
|
end
|