mofo 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/microformat.rb +6 -7
- data/lib/microformat/simple.rb +2 -2
- data/lib/mofo/adr.rb +2 -1
- data/test/fixtures/bob.html +3 -0
- data/test/hcard_test.rb +4 -0
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/microformat.rb
CHANGED
@@ -16,7 +16,7 @@ class Microformat
|
|
16
16
|
@options ||= target.is_a?(Hash) ? target : {}
|
17
17
|
[:first, :all].each { |key| target = @options[key] if @options[key] }
|
18
18
|
|
19
|
-
extract_base_url! target
|
19
|
+
extract_base_url! target
|
20
20
|
|
21
21
|
@doc = build_doc(@options[:text] ? @options : target)
|
22
22
|
|
@@ -270,7 +270,7 @@ class Microformat
|
|
270
270
|
when 'a' then element['href']
|
271
271
|
when 'object' then element['value']
|
272
272
|
end
|
273
|
-
url[/^http/] ? url : @base_url.to_s + url if url.respond_to?(:[])
|
273
|
+
url[/^http/] ? url : @options[:base_url].to_s + url if url.respond_to?(:[])
|
274
274
|
elsif target.is_a? Array
|
275
275
|
target.inject(nil) do |found, klass|
|
276
276
|
klass = klass.respond_to?(:find) ? klass : nil
|
@@ -278,7 +278,7 @@ class Microformat
|
|
278
278
|
found || parse_element(element, klass)
|
279
279
|
end
|
280
280
|
elsif target.is_a? Class
|
281
|
-
target.find(
|
281
|
+
target.find(@options.merge(:first => element))
|
282
282
|
else
|
283
283
|
value = case element.name
|
284
284
|
when 'abbr' then element['title']
|
@@ -293,10 +293,9 @@ class Microformat
|
|
293
293
|
value.is_a?(Hash) ? OpenStruct.new(value) : value
|
294
294
|
end
|
295
295
|
|
296
|
-
def extract_base_url!(target
|
297
|
-
@base_url
|
298
|
-
@base_url ||=
|
299
|
-
@base_url ||= target[/^(http:\/\/[^\/]+)/] if target.respond_to?(:scan)
|
296
|
+
def extract_base_url!(target)
|
297
|
+
@options[:base_url] ||= @options[:base] || @options[:url]
|
298
|
+
@options[:base_url] ||= target[/^(http:\/\/[^\/]+)/] if target.respond_to?(:scan)
|
300
299
|
end
|
301
300
|
end
|
302
301
|
|
data/lib/microformat/simple.rb
CHANGED
@@ -9,11 +9,11 @@ class Microformat
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.find_occurences(doc)
|
12
|
-
@from ? doc/from_as_xpath : super
|
12
|
+
@from ? doc/from_as_xpath : super
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.build_class(tag)
|
16
|
-
new(tag.innerText)
|
16
|
+
new(tag.innerText || '')
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.from(options)
|
data/lib/mofo/adr.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# => http://microformats.org/wiki/adr
|
2
2
|
require 'microformat'
|
3
|
+
require 'microformat/simple'
|
3
4
|
|
4
5
|
class Adr < Microformat
|
5
6
|
one :post_office_box, :extended_address, :street_address,
|
6
|
-
:locality, :region, :
|
7
|
+
:locality, :region, :country_name, :value, :postal_code => Simple
|
7
8
|
|
8
9
|
many :type
|
9
10
|
end
|
data/test/fixtures/bob.html
CHANGED
@@ -58,6 +58,9 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
58
58
|
Cell: <span class="tel"><span class="type" style="display:none;">cell</span> <span class="value">707-555-4756</span></span><br>
|
59
59
|
|
60
60
|
|
61
|
+
<div class="adr">
|
62
|
+
Zip: <span class="postal-code">01234</span>
|
63
|
+
</div>
|
61
64
|
|
62
65
|
|
63
66
|
</div><!-- /vcard -->
|
data/test/hcard_test.rb
CHANGED
@@ -102,6 +102,10 @@ context "The parsed Bob hCard object" do
|
|
102
102
|
$bob.n.family_name.should.equal 'Smith'
|
103
103
|
end
|
104
104
|
|
105
|
+
specify "should have a valid postal code" do
|
106
|
+
$bob.adr.postal_code.should.equal '01234'
|
107
|
+
end
|
108
|
+
|
105
109
|
specify "should have a valid url" do
|
106
110
|
$bob.url.should.equal "http://nubhub.com/bob"
|
107
111
|
end
|