Class: Atom::Link
Overview
Represents a link in an Atom document.
A link defines a reference from an Atom document to a web resource.
References
See www.atomenabled.org/developers/syndication/atom-format-spec.php#element.link for a description of the different types of links.
Defined Under Namespace
Modules: Rel
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#fetch(options = {}) ⇒ Object
This will fetch the URL referenced by the link.
-
#initialize(o) ⇒ Link
constructor
Create a link.
- #inspect ⇒ Object
- #length=(v) ⇒ Object
- #to_s ⇒ Object
Methods included from Xml::Parseable
#accessor_name, #current_node_is?, #document?, included, #next_node_is?, #parse, #to_xml
Constructor Details
#initialize(o) ⇒ Link
Create a link.
o
-
An XML::Reader containing a link element or a Hash of attributes.
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/atom.rb', line 753 def initialize(o) case o when Nokogiri::XML::Reader if current_node_is?(o, 'link') parse(o, :once => true) else raise ArgumentError, "Link created with node other than atom:link: #{o.name}" end when Hash [:href, :rel, :type, :length, :hreflang, :title].each do |attr| self.send("#{attr}=", o[attr]) end else raise ArgumentError, "Don't know how to handle #{o}" end end |
Instance Method Details
#==(o) ⇒ Object
779 780 781 |
# File 'lib/atom.rb', line 779 def ==(o) o.respond_to?(:href) && o.href == self.href end |
#fetch(options = {}) ⇒ Object
This will fetch the URL referenced by the link.
If the URL contains a valid feed, a Feed will be returned, otherwise, the body of the response will be returned.
TODO: Handle redirects.
790 791 792 793 794 795 796 |
# File 'lib/atom.rb', line 790 def fetch( = {}) begin Atom::Feed.load_feed(URI.parse(self.href), ) rescue ArgumentError Net::HTTP.get_response(URI.parse(self.href)).body end end |
#inspect ⇒ Object
798 799 800 |
# File 'lib/atom.rb', line 798 def inspect "<Atom::Link href:'#{href}' type:'#{type}'>" end |
#length=(v) ⇒ Object
771 772 773 |
# File 'lib/atom.rb', line 771 def length=(v) @length = v.to_i end |
#to_s ⇒ Object
775 776 777 |
# File 'lib/atom.rb', line 775 def to_s self.href end |