Sha256: 92630b38f8034dd9e5189fff4e43dcdca2b00fcd568f65ba495ad75a458e46ca
Contents?: true
Size: 1.89 KB
Versions: 1
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true module MicroMicro module Parsers class UrlPropertyParser < BasePropertyParser HTML_ATTRIBUTES_MAP = { "href" => %w[a area link], "src" => %w[audio iframe img source video], "poster" => %w[video], "data" => %w[object] }.freeze EXTENDED_HTML_ATTRIBUTES_MAP = { "title" => %w[abbr], "value" => %w[data input] }.freeze # @see https://microformats.org/wiki/microformats2-parsing#parsing_a_u-_property # microformats.org: microformats2 parsing specification § Parsing a +u-+ property # @see https://microformats.org/wiki/microformats2-parsing#parse_an_img_element_for_src_and_alt # microformats.org: microformats2 parsing specification § Parse an img element for src and alt # # @return [String, Hash{Symbol => String}] def value @value ||= if node.matches?("img[alt], img[srcset]") ImageElementParser.new(node, resolved_value).to_h else resolved_value end end private # @return [String, nil] def attribute_value Helpers.attribute_value_from(node, HTML_ATTRIBUTES_MAP) end # @return [String, nil] def extended_attribute_value Helpers.attribute_value_from(node, EXTENDED_HTML_ATTRIBUTES_MAP) end # @return [String] def resolved_value @resolved_value ||= node.document.resolve_relative_url(unresolved_value.strip) end # @return [String] def text_content Helpers.text_content_from(node) end # @return [String] def unresolved_value attribute_value || value_class_pattern_value || extended_attribute_value || text_content end # @return [String, nil] def value_class_pattern_value ValueClassPatternParser.new(node).value end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micromicro-5.0.0 | lib/micro_micro/parsers/url_property_parser.rb |