Sha256: 54f8c600d23cd43441312e0ca2f90cc65b36a506514bc1c62e6d4ecb7bd9688a
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module MicroMicro module Collections class RelationshipsCollection < BaseCollection # @see https://microformats.org/wiki/microformats2-parsing#parse_a_hyperlink_element_for_rel_microformats # # @return [Hash{Symbol => Array<String>}] def group_by_rel 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 # @see https://microformats.org/wiki/microformats2-parsing#parse_a_hyperlink_element_for_rel_microformats # # @return [Hash{Symbol => Hash{Symbol => Array, String}}] def group_by_url group_by(&:href).symbolize_keys.transform_values { |relationships| relationships.first.to_h.slice!(:href) } end # @return [Array<String>] def rels @rels ||= flat_map(&:rels).uniq.sort end # @return [Array<String>] def urls @urls ||= map(&:href).uniq.sort end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
micromicro-2.0.1 | lib/micro_micro/collections/relationships_collection.rb |
micromicro-2.0.0 | lib/micro_micro/collections/relationships_collection.rb |