Sha256: d4b8d75a2c9d5b8160ca98d092fe52f9008cfff4ac138f8b8ee22764d15d15d5

Contents?: true

Size: 667 Bytes

Versions: 3

Compression:

Stored size: 667 Bytes

Contents

module Rooftop
  module ResourceLinks
    class Collection < ::Array
      attr_reader :links
      def initialize(links)
        links.each do |link_type,links|
          links.each do |link|
            self << Rooftop::ResourceLinks::Link.new(link_type,link)
          end
        end
      end

      # Find links by attribute. Assume there will only be one attribute in the search
      def find_by(hash)
        raise ArgumentError, "you can only find a resource link by one attribute at a time" unless hash.length == 1
        attr = hash.first.first
        val = hash.first.last
        self.select {|l| l.send(attr) == val.to_s}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rooftop-0.0.6 lib/rooftop/resource_links/collection.rb
rooftop-0.0.5 lib/rooftop/resource_links/collection.rb
rooftop-0.0.3 lib/rooftop/resource_links/collection.rb