Class: Atom::Links
Overview
Links provides an Array of Link objects belonging to either a Feed or an Entry.
Some additional methods to get specific types of links are provided.
References
See also www.atomenabled.org/developers/syndication/atom-format-spec.php#element.link for details on link selection and link attributes.
Instance Method Summary collapse
-
#alternate(type = nil) ⇒ Object
Get the alternate.
-
#alternates ⇒ Object
Get all alternates.
-
#edit_link ⇒ Object
Gets the edit link.
-
#enclosures ⇒ Object
Gets all links with rel == ‘enclosure’.
-
#first_page ⇒ Object
Gets the link with rel == ‘first’.
-
#initialize ⇒ Links
constructor
Initialize an empty Links array.
-
#last_page ⇒ Object
Gets the link with rel == ‘last’.
-
#next_page ⇒ Object
Gets the link with rel == ‘next’.
-
#prev_page ⇒ Object
Gets the link with rel == ‘prev’.
-
#self ⇒ Object
Gets the self link.
-
#via ⇒ Object
Gets the via link.
Constructor Details
#initialize ⇒ Links
Initialize an empty Links array.
623 624 625 |
# File 'lib/atom.rb', line 623 def initialize super([]) end |
Instance Method Details
#alternate(type = nil) ⇒ Object
Get the alternate.
Returns the first link with rel == ‘alternate’ that matches the given type.
630 631 632 633 634 635 636 |
# File 'lib/atom.rb', line 630 def alternate(type = nil) 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 |
#alternates ⇒ Object
Get all alternates.
639 640 641 |
# File 'lib/atom.rb', line 639 def alternates select { |link| link.rel.nil? || link.rel == Link::Rel::ALTERNATE } end |
#edit_link ⇒ Object
Gets the edit link.
This is the link which can be used for posting updates to an item using the Atom Publishing Protocol.
690 691 692 |
# File 'lib/atom.rb', line 690 def edit_link detect { |link| link.rel == 'edit' } end |
#enclosures ⇒ Object
Gets all links with rel == ‘enclosure’
654 655 656 |
# File 'lib/atom.rb', line 654 def enclosures select { |link| link.rel == Link::Rel::ENCLOSURE } end |
#first_page ⇒ Object
Gets the link with rel == ‘first’.
This is defined as the first page in a pagination set.
661 662 663 |
# File 'lib/atom.rb', line 661 def first_page detect { |link| link.rel == Link::Rel::FIRST } end |
#last_page ⇒ Object
Gets the link with rel == ‘last’.
This is defined as the last page in a pagination set.
668 669 670 |
# File 'lib/atom.rb', line 668 def last_page detect { |link| link.rel == Link::Rel::LAST } end |
#next_page ⇒ Object
Gets the link with rel == ‘next’.
This is defined as the next page in a pagination set.
675 676 677 |
# File 'lib/atom.rb', line 675 def next_page detect { |link| link.rel == Link::Rel::NEXT } end |
#prev_page ⇒ Object
Gets the link with rel == ‘prev’.
This is defined as the previous page in a pagination set.
682 683 684 |
# File 'lib/atom.rb', line 682 def prev_page detect { |link| link.rel == Link::Rel::PREVIOUS } end |