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 CHANGED
@@ -1,2 +1,6 @@
1
+ 2009-02-03
2
+ * [1.0.1] ariejan - Bumped to 1.0.1
3
+ * ariejan - Separated Armory and Character into a module named Warcraft.
4
+ * ariejan - Updated README to reflect the correct naming of the gem.
1
5
  2008-08-14
2
6
  * [1.0.0] ariejan - Initial release
@@ -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-warcraft-armory --source http://gems.github.com</pre>
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>require 'warcraft-armory'</code></pre>
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 = WarcraftAmory.find(:eu, 'Aszune', 'Nosius')</code></pre>
42
+ <pre><code>character = Warcraft::Amory.find(:eu, 'Aszune', 'Adries')</code></pre>
40
43
 
41
- This will either return a WarcraftCharacter object or nil when not character information was found.
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
 
@@ -1,34 +1,43 @@
1
1
  require 'hpricot'
2
2
  require 'open-uri'
3
3
 
4
- class WarcraftCharacter
5
- attr_accessor :name, :level, :guild, :race, :class_name
6
- end
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
- protected
19
+ protected
19
20
 
20
- def self.parse_html(html)
21
- char = WarcraftCharacter.new
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
- details = (html/"div.character-outer").inner_text.strip.split("\n")
24
- small_details = details[4].split('?')
25
-
26
- char.name = details[0]
27
- char.guild = details[2]
28
- char.level = small_details[1]
29
- char.race = small_details[2]
30
- char.class_name = small_details[3]
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
- char
33
- end
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 = WarcraftArmory.parse_html(@html)
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 WarcraftCharacter, character.class
37
+ assert_equal Warcraft::Character, character.class
37
38
  end
38
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ariejan-warcraft_armory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariejan de Vroom