jxl-lewtlynx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lewtlynx.gemspec +24 -0
- data/lib/lewtcloth.rb +14 -0
- data/lib/lewtlynx.rb +61 -0
- data/spec/lewtcloth_spec.rb +13 -0
- data/spec/lewtlynx_spec.rb +38 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/stubs/invalid.xml +1 -0
- data/spec/stubs/valid.xml +1 -0
- metadata +60 -0
data/lewtlynx.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "lewtlynx"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2008-12-13"
|
5
|
+
s.summary = "wowhead links ftw"
|
6
|
+
s.email = "jxl@ganja.nl"
|
7
|
+
s.homepage = "http://github.com/jxl/lewtlynx"
|
8
|
+
s.description = "wowhead links ftw"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.author = "Ron Damen"
|
11
|
+
s.files = [
|
12
|
+
"lewtlynx.gemspec",
|
13
|
+
"lib/lewtlynx.rb",
|
14
|
+
"lib/lewtcloth.rb"
|
15
|
+
]
|
16
|
+
s.test_files = [
|
17
|
+
"spec/spec_helper.rb",
|
18
|
+
"spec/spec.opts",
|
19
|
+
"spec/lewtlynx_spec.rb",
|
20
|
+
"spec/lewtcloth_spec.rb",
|
21
|
+
"spec/stubs/valid.xml",
|
22
|
+
"spec/stubs/invalid.xml"
|
23
|
+
]
|
24
|
+
end
|
data/lib/lewtcloth.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lewtlynx')
|
2
|
+
|
3
|
+
module LewtCloth
|
4
|
+
include LewtLynx
|
5
|
+
def lewt(text)
|
6
|
+
text.gsub!(/\[\[(.+)\]\]/) do |m|
|
7
|
+
Item.new($1).link
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# RedCloth.send(:include, LewtCloth)
|
13
|
+
# input = "i hope [spirit world glass] drops"
|
14
|
+
# output = RedCloth.new(input).to_html(:textile, :lewt)
|
data/lib/lewtlynx.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module LewtLynx
|
6
|
+
class Item
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :quality
|
9
|
+
attr_reader :qid
|
10
|
+
attr_reader :url
|
11
|
+
attr_reader :link
|
12
|
+
|
13
|
+
def initialize(query)
|
14
|
+
@query = query
|
15
|
+
valid? ? parse : @link = query
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse
|
19
|
+
@name = xml.xpath('//name').inner_text
|
20
|
+
@quality = xml.xpath('//quality').inner_text
|
21
|
+
@qid = xml.xpath('//quality').attr("id")
|
22
|
+
@url = xml.xpath('//link').inner_text
|
23
|
+
@link = "<a class=\"q#{@qid}\" href=\"#{@url}\">#{@name}</a>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def xml
|
27
|
+
Request.new(query_url).xml
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_url
|
31
|
+
"http://www.wowhead.com/?item=#{format_query}&xml"
|
32
|
+
end
|
33
|
+
|
34
|
+
def format_query
|
35
|
+
@query.downcase!
|
36
|
+
@query.gsub!("'", "")
|
37
|
+
@query.gsub!('"', "")
|
38
|
+
@query.strip!
|
39
|
+
@query.gsub(/\s+/,"+")
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid?
|
43
|
+
!!xml.xpath('/wowhead/error').empty? &&
|
44
|
+
!xml.xpath('/wowhead/item').empty?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Request
|
49
|
+
def initialize(url)
|
50
|
+
@url = url
|
51
|
+
end
|
52
|
+
|
53
|
+
def xml
|
54
|
+
@xml ||= Nokogiri.XML(get)
|
55
|
+
end
|
56
|
+
|
57
|
+
def get
|
58
|
+
@get ||= open(@url).read
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require 'redcloth'
|
3
|
+
|
4
|
+
describe LewtCloth do
|
5
|
+
describe "parse" do
|
6
|
+
it "makes a pretty link" do
|
7
|
+
RedCloth.send(:include, LewtCloth)
|
8
|
+
input = "i hope [[spirit world glass]] drops"
|
9
|
+
output = RedCloth.new(input).to_html(:textile, :lewt)
|
10
|
+
output.should == "<p>i hope <a class=\"q4\" href=\"http://www.wowhead.com/?item=42284\">Hateful Gladiator’s Slicer</a> drops</p>"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe LewtLynx do
|
4
|
+
describe "item" do
|
5
|
+
before(:each) do
|
6
|
+
@item = LewtLynx::Item.new('hateful slicer')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "makes a pretty link" do
|
10
|
+
@item.link.should ===
|
11
|
+
"<a class=\"q4\" href=\"http://www.wowhead.com/?item=42284\">" +
|
12
|
+
"Hateful Gladiator's Slicer" +
|
13
|
+
"</a>"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gets info" do
|
17
|
+
@item.name.should === "Hateful Gladiator's Slicer"
|
18
|
+
@item.quality.should === "Epic"
|
19
|
+
@item.qid.should === "4"
|
20
|
+
@item.url.should === "http://www.wowhead.com/?item=42284"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "composes query url" do
|
24
|
+
@item.query_url.should ==
|
25
|
+
"http://www.wowhead.com/?item=hateful+slicer&xml"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "formats query for url" do
|
29
|
+
@item.format_query.should == "hateful+slicer"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "return set link to query when invalid" do
|
33
|
+
request_invalid
|
34
|
+
@item = LewtLynx::Item.new('hateful slicer')
|
35
|
+
@item.link.should == 'hateful slicer'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), "../lib/lewtlynx")
|
5
|
+
require File.join(File.dirname(__FILE__), "../lib/lewtcloth")
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
config.mock_with :mocha
|
9
|
+
config.before do
|
10
|
+
request_valid
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def request(type)
|
15
|
+
stub = open(File.join(File.dirname(__FILE__), "stubs/#{type}.xml")).read
|
16
|
+
LewtLynx::Request.any_instance.stubs(:get).returns(stub)
|
17
|
+
end
|
18
|
+
|
19
|
+
def request_valid
|
20
|
+
request(:valid)
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_invalid
|
24
|
+
request(:invalid)
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><wowhead><error>Item not found!</error></wowhead>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><wowhead><item id="42284"><name><![CDATA[Hateful Gladiator's Slicer]]></name><level>200</level><quality id="4">Epic</quality><class id="2"><![CDATA[Weapons]]></class><subclass id="7"><![CDATA[One-Handed Swords]]></subclass><icon displayId="57298">INV_Sword_86</icon><inventorySlot id="13">One-Hand</inventorySlot><htmlTooltip><![CDATA[<table><tr><td><b class="q4">Hateful Gladiator's Slicer</b><br />Binds when picked up<table width="100%"><tr><td>One-Hand</td><th>Sword</th></tr></table><table width="100%"><tr><td>298 - 448 Damage</td><th>Speed 2.60</th></tr></table>(143.5 damage per second)<br />+58 Stamina<!--e--><br />Durability 105 / 105<br />Requires Level 80</td></tr></table><table><tr><td><span class="q2">Equip: Improves critical strike rating by 26 <small>(<!--r80:32:26-->0.57% @ L80)</small>.</span><br /><span class="q2">Equip: Improves your resilience rating by 25 <small>(<!--r80:35:25-->0.3% @ L80)</small>.</span><br /><span class="q2">Equip: Increases attack power by 76.</span></td></tr></table>]]></htmlTooltip><json><![CDATA[id:42284,name:'3Hateful Gladiator\'s Slicer',level:200,reqlevel:80,dps:143.5,speed:2.60,slot:13,classs:2,subclass:7]]></json><jsonEquip><![CDATA[slotbak:13,displayid:57298,reqlevel:80,dmgmin1:298,dmgmax1:448,dmgtype1:0,speed:2.60,atkpwr:76,critstrkrtng:26,resirtng:25,sta:58,dura:105,dps:143.5,mledps:143.5,mledmgmin:298,mledmgmax:448,mlespeed:2.60]]></jsonEquip><link>http://www.wowhead.com/?item=42284</link></item></wowhead>
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jxl-lewtlynx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ron Damen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-13 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: wowhead links ftw
|
17
|
+
email: jxl@ganja.nl
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lewtlynx.gemspec
|
26
|
+
- lib/lewtlynx.rb
|
27
|
+
- lib/lewtcloth.rb
|
28
|
+
has_rdoc: false
|
29
|
+
homepage: http://github.com/jxl/lewtlynx
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.2.0
|
51
|
+
signing_key:
|
52
|
+
specification_version: 2
|
53
|
+
summary: wowhead links ftw
|
54
|
+
test_files:
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/lewtlynx_spec.rb
|
58
|
+
- spec/lewtcloth_spec.rb
|
59
|
+
- spec/stubs/valid.xml
|
60
|
+
- spec/stubs/invalid.xml
|