Sha256: ae2d6adae3c0b8b8ec70512e2d88557b801355ee83f6d5155106f807109ec41b

Contents?: true

Size: 669 Bytes

Versions: 5

Compression:

Stored size: 669 Bytes

Contents

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

      #-------------------------
      # 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.
      #
      def link_for(type)
        if link = self.links.find { |link| link.type == type }
          link.to_s
        end
      end
    end # LinkAssociation
  end # Concern
end # NPR

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
npr-3.0.0 lib/npr/concern/links_association.rb
npr-2.0.2 lib/npr/concern/links_association.rb
npr-2.0.1 lib/npr/concern/links_association.rb
npr-2.0.0 lib/npr/concern/links_association.rb
npr-1.2.0 lib/npr/concern/links_association.rb