mofo 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/mofo/xfn.rb +29 -2
- data/test/fixtures/xfn.html +7 -0
- data/test/xfn_test.rb +6 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/mofo/xfn.rb
CHANGED
@@ -2,6 +2,27 @@ $:.unshift 'lib'
|
|
2
2
|
require 'microformat'
|
3
3
|
|
4
4
|
class XFN < Microformat
|
5
|
+
@@valid_relations = %w(
|
6
|
+
contact
|
7
|
+
acquaintance
|
8
|
+
friend
|
9
|
+
met
|
10
|
+
co-worker
|
11
|
+
colleague
|
12
|
+
co-resident
|
13
|
+
neighbor
|
14
|
+
child
|
15
|
+
parent
|
16
|
+
sibling
|
17
|
+
spouse
|
18
|
+
kin
|
19
|
+
muse
|
20
|
+
crush
|
21
|
+
date
|
22
|
+
sweetheart
|
23
|
+
me
|
24
|
+
)
|
25
|
+
|
5
26
|
class Link < OpenStruct
|
6
27
|
def initialize(*args)
|
7
28
|
super
|
@@ -35,9 +56,15 @@ class XFN < Microformat
|
|
35
56
|
|
36
57
|
def initialize(doc)
|
37
58
|
@links = doc.search("a[@rel]").map do |rl|
|
38
|
-
relation = rl[:rel].
|
59
|
+
relation = rl[:rel].split(' ')
|
60
|
+
|
61
|
+
# prune invalid relations
|
62
|
+
relation.each { |r| relation.delete(r) unless @@valid_relations.include? r }
|
63
|
+
relation = relation.first if relation.size == 1
|
64
|
+
next if relation.empty?
|
65
|
+
|
39
66
|
Link.new(:name => rl.innerHTML, :link => rl[:href], :relation => relation)
|
40
|
-
end
|
67
|
+
end.compact
|
41
68
|
end
|
42
69
|
|
43
70
|
def relations
|
data/test/fixtures/xfn.html
CHANGED
@@ -160,6 +160,13 @@
|
|
160
160
|
<dt>Geographical - multiple values</dt>
|
161
161
|
<dd><a href="#co-resident" rel="co-resident neighbor">co-resident + neighbor</a></dd>
|
162
162
|
</dl>
|
163
|
+
|
164
|
+
<dl class="invalid">
|
165
|
+
<dt>Reserved rels</dt>
|
166
|
+
<dd><a href="#nofollow" rel="nofollow">nofollow</a></dd>
|
167
|
+
<dd><a href="#nofollow" rel="friend nofollow">friend + nofollow</a></dd>
|
168
|
+
<dd><a href="#bookmark" rel="bookmark">bookmark</a></dd>
|
169
|
+
</dl>
|
163
170
|
|
164
171
|
<dl class="invalid">
|
165
172
|
<dt>Family - multiple values</dt>
|
data/test/xfn_test.rb
CHANGED
@@ -42,6 +42,12 @@ context "A XFN object" do
|
|
42
42
|
intersection = $xfn.colleague_and_sweetheart_and_muse_and_crush
|
43
43
|
intersection.should.be.nil
|
44
44
|
end
|
45
|
+
|
46
|
+
specify "should not pick up reserved relationships" do
|
47
|
+
$xfn.nofollow.should.be.nil
|
48
|
+
$xfn.friend_and_nofollow.should.be.nil
|
49
|
+
$xfn.bookmark.should.be.nil
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
context "A XFN::Link object" do
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mofo
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.2.10
|
7
|
+
date: 2007-08-17 00:00:00 -07:00
|
8
8
|
summary: mofo is a ruby microformat parser
|
9
9
|
require_paths:
|
10
10
|
- lib
|