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 paragraph/block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ HTML



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

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

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



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

def blocks
  @blocks
end

#docObject (readonly)

Returns the value of attribute doc.



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

def doc
  @doc
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 paragraph/block.



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

def extract!
  @blocks = doc.css('body').children.map { |child| Block.new(child).tap(&:process!) }
  @results = @blocks.reject { |b| b.result.nil? }.map(&:result)
end