Sha256: 6ee9af4b6eed003dee6def2394abf3d4f35c5cc26bcf9027b9023723ed0353c2

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

module MicroMicro
  module Collections
    class RelationsCollection < BaseCollection
      # @see microformats2 Parsing Specification section 1.4
      # @see http://microformats.org/wiki/microformats2-parsing#parse_a_hyperlink_element_for_rel_microformats
      #
      # @return [Hash{Symbole => Hash{Symbol => Array, String}}]
      def group_by_url
        group_by(&:href).symbolize_keys.transform_values { |relations| relations.first.to_h.slice!(:href) }
      end

      # @see microformats2 Parsing Specification section 1.4
      # @see http://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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
micromicro-0.1.0 lib/micro_micro/collections/relations_collection.rb