Class: Escapement::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/escapement/html.rb

Overview

Wrapper around the entire document, which contains an array of results. Each result is the text value and entities for a single element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ HTML

Returns a new instance of HTML.



8
9
10
11
12
# File 'lib/escapement/html.rb', line 8

def initialize(html)
  @doc = Nokogiri::HTML(html)
  @elements = []
  @results = nil
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



6
7
8
# File 'lib/escapement/html.rb', line 6

def doc
  @doc
end

#elementsObject (readonly)

Returns the value of attribute elements.



6
7
8
# File 'lib/escapement/html.rb', line 6

def elements
  @elements
end

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/escapement/html.rb', line 6

def results
  @results
end

Instance Method Details

#extract!Object

Extracts all of the entities for each element.



15
16
17
18
19
20
# File 'lib/escapement/html.rb', line 15

def extract!
  preprocess!

  @elements = doc.css('body').children.map { |child| Element.factory(child) }.compact
  @results = @elements.each(&:process!).reject { |e| e.result.nil? }.map(&:result)
end