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