xfn_stone 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -1
- data/lib/xfn_stone/document.rb +19 -6
- data/lib/xfn_stone/person.rb +7 -3
- data/lib/xfn_stone.rb +1 -1
- data/spec/person.rb +8 -6
- metadata +2 -2
data/History.txt
CHANGED
data/lib/xfn_stone/document.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
|
-
require 'rexml/document'
|
1
|
+
#require 'rexml/document'
|
2
|
+
#we're parsing HTML now
|
3
|
+
require 'hpricot'
|
2
4
|
|
3
5
|
module XfnStone
|
4
|
-
# This is an empty subclass of
|
6
|
+
# This is an empty subclass of hpricot. Substuting a
|
5
7
|
# different XML parser in the future will be easier this way.
|
6
8
|
# Also a useful spot for future helpers.
|
7
|
-
class Document
|
8
|
-
def
|
9
|
-
Document.
|
9
|
+
class Document
|
10
|
+
def load(uri)
|
11
|
+
@document = Hpricot(Document.open(uri.to_s))
|
12
|
+
end
|
13
|
+
|
14
|
+
def elements(xpath)
|
15
|
+
(@document/xpath)
|
16
|
+
end
|
17
|
+
|
18
|
+
# allow the open-uri call to be stubed
|
19
|
+
def self.open(url)
|
20
|
+
Kernel.open(url)
|
10
21
|
end
|
11
22
|
end
|
12
|
-
|
23
|
+
|
24
|
+
class Element < Hpricot::Elem
|
13
25
|
end
|
26
|
+
|
14
27
|
end
|
data/lib/xfn_stone/person.rb
CHANGED
@@ -5,12 +5,16 @@ module XfnStone
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def refresh
|
8
|
-
@document = Document.
|
9
|
-
@
|
8
|
+
@document = Document.new
|
9
|
+
@document.load(@uri)
|
10
10
|
end
|
11
11
|
|
12
12
|
def friends
|
13
|
-
@
|
13
|
+
@document.elements("//a[@rel~=\"friend\"]")
|
14
|
+
end
|
15
|
+
|
16
|
+
def mine
|
17
|
+
@document.elements("//a[@rel~=\"me\"]")
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
data/lib/xfn_stone.rb
CHANGED
data/spec/person.rb
CHANGED
@@ -8,23 +8,25 @@ describe XfnStone::Person do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should parse the XML loaded from the inital URL" do
|
11
|
+
XfnStone::Document.should_receive(:open).and_return("")
|
11
12
|
url = "http://localhost"
|
12
13
|
person = XfnStone::Person.new(url)
|
13
|
-
XfnStone::Document.should_receive(:load).and_return(XfnStone::Document.new)
|
14
14
|
person.refresh
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should return the friends found in the document" do
|
18
|
-
|
19
|
-
person = XfnStone::Person.new(url)
|
20
|
-
XfnStone::Document.should_receive(:load).and_return(XfnStone::Document.new("
|
18
|
+
XfnStone::Document.should_receive(:open).and_return("
|
21
19
|
<?xml ?>
|
20
|
+
<a rel=\"me\">blog</a>
|
22
21
|
<persons>
|
23
22
|
<a rel=\"friend\">bob</a>
|
24
|
-
<a rel=\"friend\">jane</a>
|
25
|
-
</persons>")
|
23
|
+
<a rel=\"friend met\">jane</a>
|
24
|
+
</persons>")
|
25
|
+
url = "http://localhost"
|
26
|
+
person = XfnStone::Person.new(url)
|
26
27
|
person.refresh
|
27
28
|
person.friends.size.should == 2
|
29
|
+
person.mine.size.should == 1
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xfn_stone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Park
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|