Sha256: 697631510ebcd55dc115a989923b147fabfa0d45423035b5e421095b10a3b201
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
module MicroMicro module Parsers class ImpliedUrlPropertyParser < BasePropertyParser HTML_ELEMENTS_MAP = { 'a' => 'href', 'area' => 'href' }.freeze # @see http://microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties # # @return [String, nil] def value @value ||= value_node[HTML_ELEMENTS_MAP[value_node.name]] if value_node end private # @return [Array<String>] def attribute_values @attribute_values ||= begin HTML_ELEMENTS_MAP.map do |element, attribute| node if node.matches?("#{element}[#{attribute}]") end.compact end end # @return [Nokogiri::XML::Element, nil] def value_node @value_node ||= begin return attribute_values.first if attribute_values.any? HTML_ELEMENTS_MAP.each do |element, attribute| child_node = node.at_css("> #{element}[#{attribute}]:only-of-type") return child_node if child_node && !Item.item_node?(child_node) && element == child_node.name && child_node[attribute] end if node.element_children.one? && !Item.item_node?(node.first_element_child) HTML_ELEMENTS_MAP.each do |element, attribute| child_node = node.first_element_child.at_css("> #{element}[#{attribute}]:only-of-type") return child_node if child_node && !Item.item_node?(child_node) && element == child_node.name && child_node[attribute] end end nil end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micromicro-1.0.0 | lib/micro_micro/parsers/implied_url_property_parser.rb |