diff --git a/lib/atom.rb b/lib/atom.rb
index d143e7e..50011e8 100644
--- a/lib/atom.rb
+++ b/lib/atom.rb
@@ -573,7 +573,11 @@ def initialize
#
# Returns the first link with rel == 'alternate' that matches the given type.
def alternate(type = nil)
- detect { |link| (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) }
+ detect { |link|
+ (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) && (link.hreflang.nil?)
+ } || detect { |link|
+ (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type)
+ }
end
# Get all alternates.
@@ -654,7 +658,7 @@ module Rel # :nodoc:
end
include Xml::Parseable
- attribute :href, :rel, :type, :length
+ attribute :href, :rel, :type, :length, :hreflang
# Create a link.
#
@@ -669,7 +673,7 @@ def initialize(o)
raise ArgumentError, "Link created with node other than atom:link: #{o.name}"
end
when Hash
- [:href, :rel, :type, :length].each do |attr|
+ [:href, :rel, :type, :length, :hreflang].each do |attr|
self.send("#{attr}=", o[attr])
end
else
diff --git a/spec/atom_spec.rb b/spec/atom_spec.rb
index affe57d..5f651ec 100644
--- a/spec/atom_spec.rb
+++ b/spec/atom_spec.rb
@@ -654,6 +654,20 @@
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/example')
end
end
+
+ describe 'linktest9' do
+ before(:all) do
+ @entry = @entries[8]
+ end
+
+ it "should parse all links" do
+ @entry.should have(3).links
+ end
+
+ it "should pick the alternate without hreflang" do
+ @entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
+ end
+ end
end
describe 'ordertest.atom' do
diff --git a/spec/conformance/linktests.xml b/spec/conformance/linktests.xml
index c335184..41c479a 100644
--- a/spec/conformance/linktests.xml
+++ b/spec/conformance/linktests.xml
@@ -90,4 +90,14 @@
+
+ tag:snellspace.com,2006:/atom/conformance/linktest/8
+ Entry with links in different languages
+ 2005-01-18T15:00:06Z
+ The aggregator should pick the second link as alternate.
+
+
+
+
+