Class: Webspinne::Index

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/webspinne/index.rb

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



5
6
7
# File 'lib/webspinne/index.rb', line 5

def initialize
  @list = {}
end

Instance Method Details

#<<(link) ⇒ Object

defensive set



16
17
18
# File 'lib/webspinne/index.rb', line 16

def << link
  @list[link.uri] ||= link
end

#each(&block) ⇒ Object



9
10
11
12
13
# File 'lib/webspinne/index.rb', line 9

def each &block
  @list.each do |uri, link|
    block.call link
  end
end


24
25
26
# File 'lib/webspinne/index.rb', line 24

def next_unvisited_onsite_link
  find { |link| !link.visited? && link.onsite? }
end

#offsite_sizeObject



40
41
42
# File 'lib/webspinne/index.rb', line 40

def offsite_size
  size - onsite_size
end

#onsite_sizeObject



36
37
38
# File 'lib/webspinne/index.rb', line 36

def onsite_size
  find_all { |link| link.onsite? }.size
end

#sizeObject



20
21
22
# File 'lib/webspinne/index.rb', line 20

def size
  @list.size
end

#unvisited_sizeObject



32
33
34
# File 'lib/webspinne/index.rb', line 32

def unvisited_size
  size - visited_size
end

#visited_sizeObject



28
29
30
# File 'lib/webspinne/index.rb', line 28

def visited_size
  find_all { |link| link.visited? }.size
end