Sha256: 9fd23b94068454ef26106414bd84c8f7efad58667231bc285c7991d4e3e5f563
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
# Author:: TAC (tac@tac42.net) require_relative 'yasuri_node' module Yasuri class PaginateNode include Node def initialize(xpath, name, children = [], limit: nil, flatten: false) super(xpath, name, children) @flatten = flatten @limit = limit end def inject(agent, page, opt = {}, element = page) retry_count = opt[:retry_count] || Yasuri::DefaultRetryCount raise NotImplementedError.new("PagenateNode inside StructNode, Not Supported") if page != element child_results = [] limit = @limit.nil? ? Float::MAX : @limit while page child_results_kv = @children.map do |child_node| child_name = Yasuri.node_name(child_node.name, opt) [child_name, child_node.inject(agent, page, opt)] end child_results << Hash[child_results_kv] link = page.search(@xpath).first # Todo raise: link is not found break if link == nil link_button = Mechanize::Page::Link.new(link, agent, page) page = Yasuri.with_retry(retry_count) { link_button.click } break if (limit -= 1) <= 0 end if @flatten == true return child_results.map{|h| h.values}.flatten end child_results end def opts {limit:@limit, flatten:@flatten} end def node_type_str "pages".freeze end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yasuri-3.2.0 | lib/yasuri/yasuri_paginate_node.rb |