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.
@@ -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 load(uri)
11
- @document = Hpricot(Document.open(uri.to_s))
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)
@@ -1,12 +1,18 @@
1
1
  module XfnStone
2
2
  class Person
3
- def initialize(url)
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.new
9
- @document.load(@uri)
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
@@ -8,5 +8,5 @@ require 'xfn_stone/document.rb'
8
8
  require 'xfn_stone/person.rb'
9
9
 
10
10
  module XfnStone
11
- VERSION = '0.0.2'
11
+ VERSION = '0.0.4'
12
12
  end
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 take an initial URL" do
6
- person = XfnStone::Person.new("http://localhost")
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 parse the XML loaded from the inital URL" do
11
- XfnStone::Document.should_receive(:open).and_return("")
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 friends found in the document" do
18
- XfnStone::Document.should_receive(:open).and_return("
19
- <?xml ?>
20
- <a rel=\"me\">blog</a>
21
- <persons>
22
- <a rel=\"friend\">bob</a>
23
- <a rel=\"friend met\">jane</a>
24
- </persons>")
25
- url = "http://localhost"
26
- person = XfnStone::Person.new(url)
27
- person.refresh
28
- person.friends.size.should == 2
29
- person.mine.size.should == 1
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.2
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-23 00:00:00 -08:00
12
+ date: 2008-02-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency