Sha256: c4253dcaf452278d3c50d75d080319f7a989690a17b2d96f40ab7e04815aa7f6

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 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
      #   microformats.org: microformats2 parsing specification ยง 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.delete_if { |child_node| child_node.nil? || Helpers.item_node?(child_node) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
micromicro-5.0.1 lib/micro_micro/parsers/implied_url_property_parser.rb
micromicro-5.0.0 lib/micro_micro/parsers/implied_url_property_parser.rb