class Tango::LinkStack

Stack of links to be crawled

@author Mckomo

Attributes

host[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
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