xfn_stone 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xfn_stone/document.rb +9 -2
- data/lib/xfn_stone/person.rb +9 -3
- data/lib/xfn_stone.rb +1 -1
- data/spec/person.rb +17 -21
- metadata +2 -2
data/lib/xfn_stone/document.rb
CHANGED
@@ -7,8 +7,15 @@ module XfnStone
|
|
7
7
|
# different XML parser in the future will be easier this way.
|
8
8
|
# Also a useful spot for future helpers.
|
9
9
|
class Document
|
10
|
-
def
|
11
|
-
|
10
|
+
def self.create_from_uri(uri)
|
11
|
+
document = Document.new
|
12
|
+
document.load_from_uri(uri)
|
13
|
+
return document
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_from_uri(uri)
|
17
|
+
file = Document.open(uri.to_s)
|
18
|
+
@document = Hpricot(file)
|
12
19
|
end
|
13
20
|
|
14
21
|
def elements(xpath)
|
data/lib/xfn_stone/person.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module XfnStone
|
2
2
|
class Person
|
3
|
-
|
3
|
+
attr_reader :uri
|
4
|
+
|
5
|
+
def initialize(url, load_now = true)
|
4
6
|
@uri = URI.parse(url)
|
7
|
+
refresh if load_now
|
5
8
|
end
|
6
9
|
|
7
10
|
def refresh
|
8
|
-
@document = Document.
|
9
|
-
|
11
|
+
@document = Document.create_from_uri(@uri)
|
12
|
+
end
|
13
|
+
|
14
|
+
def contacts
|
15
|
+
@document.elements("//a[@rel~=\"contact\"]")
|
10
16
|
end
|
11
17
|
|
12
18
|
def friends
|
data/lib/xfn_stone.rb
CHANGED
data/spec/person.rb
CHANGED
@@ -2,31 +2,27 @@ require File.join(File.dirname(__FILE__), *%w[spec_helper])
|
|
2
2
|
require File.join(File.dirname(__FILE__), *%w[../lib/xfn_stone.rb])
|
3
3
|
|
4
4
|
describe XfnStone::Person do
|
5
|
-
it "should
|
6
|
-
person
|
7
|
-
person.is_a?(XfnStone::Person).should be_true
|
5
|
+
it "should know its load URL" do
|
6
|
+
@person.uri.to_s.should == @url
|
8
7
|
end
|
9
8
|
|
10
|
-
it "should
|
11
|
-
|
12
|
-
url = "http://localhost"
|
13
|
-
person = XfnStone::Person.new(url)
|
14
|
-
person.refresh
|
9
|
+
it "should return the 'me' links found in the document" do
|
10
|
+
@person.mine.size.should == 1
|
15
11
|
end
|
16
12
|
|
17
|
-
it "should return the
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
person
|
13
|
+
it "should return the friend links found in the document" do
|
14
|
+
@person.friends.size.should == 2
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the contact links found in the document" do
|
18
|
+
@person.friends.size.should == 2
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
html_page = open(File.join(File.dirname(__FILE__),"bob.html"))
|
23
|
+
XfnStone::Document.should_receive(:open).and_return(html_page)
|
24
|
+
@url = "http://localhost"
|
25
|
+
@person = XfnStone::Person.new(@url)
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
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.4
|
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-24 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|