class Burly::Parsers::HtmlParser
@api private
def attr_nodes
-
(Nokogiri::XML::NodeSet)
-
def attr_nodes @attr_nodes ||= context_node.xpath(*ATTRIBUTES_XPATHS) end
def context_node
-
(Nokogiri::HTML5::Document, Nokogiri::XML::Element)
-
def context_node @context_node ||= doc.search(*Array(@context)).first || doc end
def doc
-
(Nokogiri::HTML5::Document)
-
def doc @doc ||= Nokogiri.HTML5(@document) end
def initialize(document, context: nil)
-
context
(String, Array
) -- -
document
() --
def initialize(document, context: nil) @context = context super end
def parse
-
(Array
-)
def parse attr_nodes.flat_map do |attr_node| if SRCSET_ATTRIBUTES_MAP.key?(attr_node.name) urls_from_candidate_strings(attr_node.value.split(/\s*,\s*/)) else attr_node.value.strip end end end
def urls_from_candidate_strings(candidate_strings)
def urls_from_candidate_strings(candidate_strings) candidate_strings.flat_map { |candidate_string| candidate_string.strip.split(/\s|$/)[0] } end