class Tango::LinkStack
Stack of links to be crawled
@author Mckomo
Attributes
host[R]
links[R]
shifted[R]
Public Class Methods
new( base_link )
click to toggle source
# File lib/tango/link_stack.rb, line 13 def initialize( base_link ) if base_link !~ URI::regexp raise ArgumentError, "'#{base_link}' is not valid website URL." end # Parse base link url = URI( base_link ) @host = "#{url.scheme}://#{url.host}:#{url.port}" # Extract host from base link @links = [] # Container for links (without host part) @shifted = 0 # Shifted links counter # Extract path (with query) from base link and append it as initial link path = url.query ? "#{url.path}?#{url.query}" : url.path append( path ) end
Public Instance Methods
append( links )
click to toggle source
Append link/s to stack
@return [Array|String]
# File lib/tango/link_stack.rb, line 45 def append( links ) if links.is_a? String @links << links elsif links.is_a? Array @links += links end end
has_links?()
click to toggle source
Check if link stack still has links
@return [Boolean]
# File lib/tango/link_stack.rb, line 56 def has_links? ! @links.empty? end
shift()
click to toggle source
Shift link from stack and get referrer content
@return [String]
# File lib/tango/link_stack.rb, line 35 def shift return unless has_links? @shifted += 1 @links.shift end