class MicroMicro::Parsers::ImpliedUrlPropertyParser

Constants

HTML_ELEMENTS_MAP

Public Instance Methods

value() click to toggle source

@see microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties

@return [String, nil]

# File lib/micro_micro/parsers/implied_url_property_parser.rb, line 12
def value
  @value ||= value_node[HTML_ELEMENTS_MAP[value_node.name]] if value_node
end

Private Instance Methods

attribute_values() click to toggle source

@return [Array<String>]

# File lib/micro_micro/parsers/implied_url_property_parser.rb, line 19
def attribute_values
  @attribute_values ||= begin
    HTML_ELEMENTS_MAP.map do |element, attribute|
      node if node.matches?("#{element}[#{attribute}]")
    end.compact
  end
end
value_node() click to toggle source

@return [Nokogiri::XML::Element, nil]

# File lib/micro_micro/parsers/implied_url_property_parser.rb, line 28
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