class MicroMicro::Collections::RelationshipsCollection

Public Instance Methods

group_by_rel() click to toggle source

@see microformats.org/wiki/microformats2-parsing#parse_a_hyperlink_element_for_rel_microformats

@return [Hash{Symbol => Array<String>}]

# File lib/micro_micro/collections/relationships_collection.rb, line 14
def group_by_rel
  # flat_map { |member| member.rels.map { |rel| [rel, member.href] } }.group_by(&:shift).symbolize_keys.transform_values(&:flatten).transform_values(&:uniq)
  each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |member, hash|
    member.rels.each { |rel| hash[rel] << member.href }
  end.symbolize_keys.transform_values(&:uniq)
end
group_by_url() click to toggle source

@see microformats.org/wiki/microformats2-parsing#parse_a_hyperlink_element_for_rel_microformats

@return [Hash{Symbol => Hash{Symbol => Array, String}}]

# File lib/micro_micro/collections/relationships_collection.rb, line 7
def group_by_url
  group_by(&:href).symbolize_keys.transform_values { |relationships| relationships.first.to_h.slice!(:href) }
end
rels() click to toggle source

@return [Array<String>]

# File lib/micro_micro/collections/relationships_collection.rb, line 22
def rels
  @rels ||= map(&:rels).flatten.uniq.sort
end
urls() click to toggle source

@return [Array<String>]

# File lib/micro_micro/collections/relationships_collection.rb, line 27
def urls
  @urls ||= map(&:href).uniq.sort
end