Sha256: 7d4dd5093a1ce796366c563efc842644291bdd11c6f615f0f246880a9a2467cb

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

require_relative 'yasuri_node'

module Yasuri
  class LinksNode
    include Node

    def inject(agent, page, opt = {}, element = page)
      retry_count = opt[:retry_count] || Yasuri::DefaultRetryCount
      interval_ms = opt[:interval_ms] || Yasuri::DefaultInterval_ms

      links = element.search(@xpath) || [] # links expected
      links.map do |link|
        link_button = Mechanize::Page::Link.new(link, agent, page)
        child_page = Yasuri.with_retry(retry_count, interval_ms) { link_button.click }

        child_results_kv = @children.map do |child_node|
          child_name = Yasuri.node_name(child_node.name, opt)
          [child_name, child_node.inject(agent, child_page, opt)]
        end

        Hash[child_results_kv]
      end
    end

    def node_type_str
      "links".freeze
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yasuri-3.3.2 lib/yasuri/yasuri_links_node.rb
yasuri-3.3.1 lib/yasuri/yasuri_links_node.rb