Class: Atom::Link
- Inherits:
-
Object
- Object
- Atom::Link
- Includes:
- Xml::Parseable
- Defined in:
- lib/atom.rb
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)
- - (Object) ==(o)
-
- (Object) fetch(options = {})
This will fetch the URL referenced by the link.
-
- (Link) initialize(o)
constructor
Create a link.
- - (Object) inspect
- - (Object) length=(v)
- - (Object) to_s
Methods included from Xml::Parseable
#accessor_name, #current_node_is?, included, #next_node_is?, #parse, #to_xml
Constructor Details
- (Link) initialize(o)
Create a link.
o |
An XML::Reader containing a link element or a Hash of attributes. |
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/atom.rb', line 723 def initialize(o) case o when 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
- (Object) ==(o)
749 750 751 |
# File 'lib/atom.rb', line 749 def ==(o) o.respond_to?(:href) && o.href == self.href end |
- (Object) fetch(options = {})
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.
760 761 762 763 764 765 766 |
# File 'lib/atom.rb', line 760 def fetch( = {}) begin Atom::Feed.load_feed(URI.parse(self.href), ) rescue ArgumentError Net::HTTP.get_response(URI.parse(self.href)).body end end |
- (Object) inspect
768 769 770 |
# File 'lib/atom.rb', line 768 def inspect "<Atom::Link href:'#{href}' type:'#{type}'>" end |
- (Object) length=(v)
741 742 743 |
# File 'lib/atom.rb', line 741 def length=(v) @length = v.to_i end |
- (Object) to_s
745 746 747 |
# File 'lib/atom.rb', line 745 def to_s self.href end |