Class: Atom::Links

Inherits:
Array
  • Object
show all
Includes:
Enumerable
Defined in:
lib/atom.rb

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

Constructor Details

#initializeLinks

Initialize an empty Links array.


659
660
661
# File 'lib/atom.rb', line 659

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.


666
667
668
669
670
671
672
# File 'lib/atom.rb', line 666

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

#alternatesObject

Get all alternates.


675
676
677
# File 'lib/atom.rb', line 675

def alternates
  select { |link| link.rel.nil? || link.rel == Link::Rel::ALTERNATE }
end

Gets the edit link.

This is the link which can be used for posting updates to an item using the Atom Publishing Protocol.


726
727
728
# File 'lib/atom.rb', line 726

def edit_link
  detect { |link| link.rel == 'edit' }
end

#enclosuresObject

Gets all links with rel == 'enclosure'


690
691
692
# File 'lib/atom.rb', line 690

def enclosures
  select { |link| link.rel == Link::Rel::ENCLOSURE }
end

#first_pageObject

Gets the link with rel == 'first'.

This is defined as the first page in a pagination set.


697
698
699
# File 'lib/atom.rb', line 697

def first_page
  detect { |link| link.rel == Link::Rel::FIRST }
end

#last_pageObject

Gets the link with rel == 'last'.

This is defined as the last page in a pagination set.


704
705
706
# File 'lib/atom.rb', line 704

def last_page
  detect { |link| link.rel == Link::Rel::LAST }
end

#next_pageObject

Gets the link with rel == 'next'.

This is defined as the next page in a pagination set.


711
712
713
# File 'lib/atom.rb', line 711

def next_page
  detect { |link| link.rel == Link::Rel::NEXT }
end

#prev_pageObject

Gets the link with rel == 'prev'.

This is defined as the previous page in a pagination set.


718
719
720
# File 'lib/atom.rb', line 718

def prev_page
  detect { |link| link.rel == Link::Rel::PREVIOUS }
end

#selfObject

Gets the self link.


680
681
682
# File 'lib/atom.rb', line 680

def self
  detect { |link| link.rel == Link::Rel::SELF }
end

#viaObject

Gets the via link.


685
686
687
# File 'lib/atom.rb', line 685

def via
  detect { |link| link.rel == Link::Rel::VIA }
end