Class: Rooftop::ResourceLinks::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/rooftop/resource_links/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(links) ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
11
# File 'lib/rooftop/resource_links/collection.rb', line 5

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

Instance Attribute Details

Returns the value of attribute links.



4
5
6
# File 'lib/rooftop/resource_links/collection.rb', line 4

def links
  @links
end

Instance Method Details

#find_by(hash) ⇒ Object

Find links by attribute. Assume there will only be one attribute in the search

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/rooftop/resource_links/collection.rb', line 14

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