Sha256: c42b0e2299154cc2c72b2bd6f555f271ca4f6089d02b10cc19dac54c6561ac38

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

module MicroMicro
  module Parsers
    class ImpliedUrlPropertyParser < BaseImpliedPropertyParser
      CSS_SELECTORS_ARRAY = ['> a[href]:only-of-type', '> area[href]:only-of-type'].freeze

      HTML_ELEMENTS_MAP = {
        'a'    => 'href',
        'area' => 'href'
      }.freeze

      # @see https://microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties
      #
      # @return [String, nil]
      def value
        @value ||= attribute_value
      end

      private

      # @return [Array]
      def child_nodes
        nodes = [node.at_css(*CSS_SELECTORS_ARRAY)]

        nodes << node.first_element_child.at_css(*CSS_SELECTORS_ARRAY) if node.element_children.one?

        nodes.compact.reject { |child_node| Helpers.item_node?(child_node) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
micromicro-2.0.1 lib/micro_micro/parsers/implied_url_property_parser.rb
micromicro-2.0.0 lib/micro_micro/parsers/implied_url_property_parser.rb