Class: Tango::LinkStack
- Inherits:
-
Object
- Object
- Tango::LinkStack
- Defined in:
- lib/tango/link_stack.rb
Overview
Stack of links to be crawled
Instance Attribute Summary (collapse)
-
- (Object) host
readonly
Returns the value of attribute host.
-
- (Object) links
readonly
Returns the value of attribute links.
-
- (Object) shifted
readonly
Returns the value of attribute shifted.
Instance Method Summary (collapse)
-
- (Array|String) append(links)
Append link/s to stack.
-
- (Boolean) has_links?
Check if link stack still has links.
-
- (LinkStack) initialize(base_link)
constructor
A new instance of LinkStack.
-
- (String) shift
Shift link from stack and get referrer content.
Constructor Details
- (LinkStack) initialize(base_link)
Returns a new instance of LinkStack
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |
Instance Attribute Details
- (Object) host (readonly)
Returns the value of attribute host
11 12 13 |
# File 'lib/tango/link_stack.rb', line 11 def host @host end |
- (Object) links (readonly)
Returns the value of attribute links
11 12 13 |
# File 'lib/tango/link_stack.rb', line 11 def links @links end |
- (Object) shifted (readonly)
Returns the value of attribute shifted
11 12 13 |
# File 'lib/tango/link_stack.rb', line 11 def shifted @shifted end |
Instance Method Details
- (Array|String) append(links)
Append link/s to stack
45 46 47 48 49 50 51 |
# 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 |
- (Boolean) has_links?
Check if link stack still has links
56 57 58 |
# File 'lib/tango/link_stack.rb', line 56 def has_links? ! @links.empty? end |
- (String) shift
Shift link from stack and get referrer content
35 36 37 38 39 |
# File 'lib/tango/link_stack.rb', line 35 def shift return unless has_links? @shifted += 1 @links.shift end |