Sha256: 832790967df865bcd263ca7e5a04d7a01158d1e38aede33afc7576b42f9eff7e
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module MicroMicro module Parsers class ImpliedNamePropertyParser < BasePropertyParser HTML_ATTRIBUTES_MAP = { 'alt' => %w[area img], 'title' => %w[abbr] }.freeze # @see https://microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties # # @return [String] def value @value ||= attribute_value || text_content end private # @return [Nokogiri::XML::NodeSet] def candidate_nodes @candidate_nodes ||= Nokogiri::XML::NodeSet.new(node.document, child_nodes.unshift(node)) end # @return [Array] def child_nodes [node.at_css('> :only-child'), node.at_css('> :only-child > :only-child')].compact.reject { |child_node| Item.item_node?(child_node) } end # @return [String, nil] def attribute_value candidate_nodes.map { |node| self.class.attribute_value_from(node, HTML_ATTRIBUTES_MAP) }.compact.first end # @return [String] def text_content @text_content ||= Document.text_content_from(node) { |context| context.css('img').each { |img| img.content = img['alt'] } } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micromicro-1.1.0 | lib/micro_micro/parsers/implied_name_property_parser.rb |