Class: ExtraLoop::ExtractionLoop
- Inherits:
-
Object
- Object
- ExtraLoop::ExtractionLoop
- Includes:
- Hookable
- Defined in:
- lib/extraloop/extraction_loop.rb
Defined Under Namespace
Modules: Exceptions
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#document ⇒ Object
Returns the value of attribute document.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#extractors ⇒ Object
Returns the value of attribute extractors.
-
#hooks ⇒ Object
Returns the value of attribute hooks.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#scraper ⇒ Object
Returns the value of attribute scraper.
Instance Method Summary collapse
-
#initialize(loop_extractor, extractors = [], document = nil, hooks = {}, scraper = nil) ⇒ ExtractionLoop
constructor
A new instance of ExtractionLoop.
- #run ⇒ Object
Methods included from Hookable
Constructor Details
#initialize(loop_extractor, extractors = [], document = nil, hooks = {}, scraper = nil) ⇒ ExtractionLoop
Returns a new instance of ExtractionLoop.
12 13 14 15 16 17 18 19 20 |
# File 'lib/extraloop/extraction_loop.rb', line 12 def initialize(loop_extractor, extractors=[], document=nil, hooks = {}, scraper = nil) @loop_extractor = loop_extractor @extractors = extractors @document = document.is_a?(String) ? @loop_extractor.parse(document) : document @records = [] @hooks = hooks @environment = ExtractionEnvironment.new(scraper, @document, @records) self end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def children @children end |
#document ⇒ Object
Returns the value of attribute document.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def document @document end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
9 10 11 |
# File 'lib/extraloop/extraction_loop.rb', line 9 def environment @environment end |
#extractors ⇒ Object
Returns the value of attribute extractors.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def extractors @extractors end |
#hooks ⇒ Object
Returns the value of attribute hooks.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def hooks @hooks end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def parent @parent end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
9 10 11 |
# File 'lib/extraloop/extraction_loop.rb', line 9 def records @records end |
#scraper ⇒ Object
Returns the value of attribute scraper.
10 11 12 |
# File 'lib/extraloop/extraction_loop.rb', line 10 def scraper @scraper end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/extraloop/extraction_loop.rb', line 22 def run run_hook(:before, @document) get_nodelist.each do |node| run_hook(:before_extract, [node]) @records << run_extractors(node) run_hook(:after_extract, [node, records.last]) end run_hook(:after, @records) self end |