Sha256: 52d8d09fc585433a16c2428c41af4bdaf42947d6ff7790aeaf95ec1dc46b68d4
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 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]') { value: resolved_value, alt: node['alt'].strip } 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-3.0.0 | lib/micro_micro/parsers/url_property_parser.rb |