Class: Nitlink::LinkCollection
- Inherits:
-
Array
- Object
- Array
- Nitlink::LinkCollection
- Defined in:
- lib/nitlink/link_collection.rb
Instance Method Summary collapse
- #by_rel(relation_type) ⇒ Object
- #to_h(options = { with_indifferent_access: true }) ⇒ Object (also: #to_hash)
Instance Method Details
#by_rel(relation_type) ⇒ Object
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_h(options = { with_indifferent_access: true }) ⇒ Object Also known as: to_hash
10 11 12 13 14 15 16 17 |
# File 'lib/nitlink/link_collection.rb', line 10 def to_h( = { with_indifferent_access: true }) = Nitlink::HashWithIndifferentAccess.new() indifferent = .key?(:with_indifferent_access) ? [:with_indifferent_access] : true hash = indifferent ? Nitlink::HashWithIndifferentAccess.new : {} each { |link| hash[link.relation_type.to_s] ||= link } hash end |