Class: Escapement::HTML
- Inherits:
-
Object
- Object
- Escapement::HTML
- 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
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#extract! ⇒ Object
Extracts all of the entities for each paragraph/block.
-
#initialize(html) ⇒ HTML
constructor
A new instance of HTML.
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
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
6 7 8 |
# File 'lib/escapement/html.rb', line 6 def blocks @blocks end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/escapement/html.rb', line 6 def doc @doc end |
#results ⇒ Object (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 |