Class: BrandLogo::ParsedDocument

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/brand_logo/html_parser.rb

Overview

Value Object wrapping a parsed HTML document. Exposes only the subset of the Nokogiri API that strategies need, preventing strategies from depending on Nokogiri directly.

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ ParsedDocument

Returns a new instance of ParsedDocument.



15
16
17
# File 'lib/brand_logo/html_parser.rb', line 15

def initialize(doc)
  @doc = T.let(doc, Nokogiri::HTML::Document)
end

Instance Method Details

#at(selector) ⇒ Object



27
28
29
# File 'lib/brand_logo/html_parser.rb', line 27

def at(selector)
  @doc.at(selector)
end

#base_hrefObject



33
34
35
36
37
38
# File 'lib/brand_logo/html_parser.rb', line 33

def base_href
  node = @doc.at('base')
  return nil unless node

  node['href']
end

#css(selector) ⇒ Object



21
22
23
# File 'lib/brand_logo/html_parser.rb', line 21

def css(selector)
  @doc.css(selector).to_a
end