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
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#shifted ⇒ Object
readonly
Returns the value of attribute shifted.
Instance Method Summary collapse
-
#append(links) ⇒ Array|String
Append link/s to stack.
-
#has_links? ⇒ Boolean
Check if link stack still has links.
-
#initialize(base_link) ⇒ LinkStack
constructor
A new instance of LinkStack.
-
#shift ⇒ String
Shift link from stack and get referrer content.
Constructor Details
#initialize(base_link) ⇒ LinkStack
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/tango/link_stack.rb', line 11 def host @host end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
11 12 13 |
# File 'lib/tango/link_stack.rb', line 11 def links @links end |
#shifted ⇒ Object (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
#append(links) ⇒ Array|String
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 |
#has_links? ⇒ Boolean
Check if link stack still has links
56 57 58 |
# File 'lib/tango/link_stack.rb', line 56 def has_links? ! @links.empty? end |
#shift ⇒ String
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 |