Method: HtmlEntry::PageFetcher#fetch

Defined in:
lib/html_entry/page_fetcher.rb

#fetch(document) ⇒ Hash

Fetch entities from document

Parameters:

  • document (Nokogiri::HTML::Document)

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/html_entry/page_fetcher.rb', line 27

def fetch(document)
  items = []
  if instructions[:block].nil?
    # "block" instructions is not defined
    block_document = if document.instance_of?(Nokogiri::HTML::Document)
                       fetch_block_document(
                           document,
                           type:     :selector,
                           selector: 'body'
                       ).first
                     else
                       document
                     end

    fetch_data(block_document, instructions[:entity]).each do |element|
      items.push element
    end
  else
    # fetch each "block" and process entities
    fetch_block_document(document, instructions[:block]).each do |block_document|
      fetch_data(block_document, instructions[:entity]).each do |element|
        items.push element
      end
    end
  end
  items
end