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 CHANGED
@@ -1,4 +1,9 @@
1
- === 1.0.0 / 2008-02-19
1
+ === 0.0.2 / 2008-02-23
2
+
3
+ * Moved from REXML to Hpricot
4
+ * Hpricot can handle lots of pseudo-xml
5
+
6
+ === 0.0.1 / 2008-02-19
2
7
 
3
8
  * 1 major enhancement
4
9
  * Birthday!
@@ -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 REXML::Document. Substuting a
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 < REXML::Document
8
- def self.load(uri)
9
- Document.new(open(uri.to_s))
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
- class Element < REXML::Element
23
+
24
+ class Element < Hpricot::Elem
13
25
  end
26
+
14
27
  end
@@ -5,12 +5,16 @@ module XfnStone
5
5
  end
6
6
 
7
7
  def refresh
8
- @document = Document.load(@uri)
9
- @document_root = @document.elements["/"]
8
+ @document = Document.new
9
+ @document.load(@uri)
10
10
  end
11
11
 
12
12
  def friends
13
- @document_root.elements.to_a("//a[@rel=\"friend\"]")
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
@@ -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.1'
11
+ VERSION = '0.0.2'
12
12
  end
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
- url = "http://localhost"
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.1
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-19 00:00:00 -08:00
12
+ date: 2008-02-23 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency