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 ⇒ 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
Constructor Details
#initialize(o) ⇒ Link
Create a link.
o
-
An XML::Reader containing a link element or a Hash of attributes.
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/atom.rb', line 677 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].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
703 704 705 |
# File 'lib/atom.rb', line 703 def ==(o) o.respond_to?(:href) && o.href == self.href end |
#fetch ⇒ 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.
714 715 716 717 718 719 720 721 722 |
# File 'lib/atom.rb', line 714 def fetch content = Net::HTTP.get_response(URI.parse(self.href)).body begin Atom::Feed.load_feed(content) rescue ArgumentError, ParseError => ae content end end |
#inspect ⇒ Object
724 725 726 |
# File 'lib/atom.rb', line 724 def inspect "<Atom::Link href:'#{href}' type:'#{type}'>" end |
#length=(v) ⇒ Object
695 696 697 |
# File 'lib/atom.rb', line 695 def length=(v) @length = v.to_i end |
#to_s ⇒ Object
699 700 701 |
# File 'lib/atom.rb', line 699 def to_s self.href end |