Module: NPR::Concern::LinksAssociation

Included in:
Entity::Byline, Entity::List, Entity::Parent, Entity::RelatedLink, Entity::Story
Defined in:
lib/npr/concern/links_association.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/npr/concern/links_association.rb', line 4

def self.included(base)
  base.has_many "links", :key => "link", :class_name => NPR::Entity::Link
end

Instance Method Details


Find links of the passed in type.

Example:

story.link_for("html")    #=> http://npr.org/...
story.link_for("nothing") #=> nil

Returns an the content of that link if found, or nil if not found.



19
20
21
22
23
# File 'lib/npr/concern/links_association.rb', line 19

def link_for(type)
  if link = self.links.find { |link| link.type == type }
    link.to_s
  end
end