Class: Nitlink::LinkCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/nitlink/link_collection.rb

Instance Method Summary collapse

Instance Method Details

#by_rel(relation_type) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/nitlink/link_collection.rb', line 5

def by_rel(relation_type)
  raise ArgumentError.new('relation_type cannot be blank') if (!relation_type || relation_type.empty?)
  find { |link| link.relation_type == relation_type.downcase.to_s }
end

#to_hObject



10
11
12
13
14
# File 'lib/nitlink/link_collection.rb', line 10

def to_h
  hash = HashWithIndifferentAccess.new
  each { |link| hash[link.relation_type] ||= link }
  hash
end