Class: SLA::Checker

Inherits:
Object
  • Object
show all
Includes:
Colsole
Defined in:
lib/sla/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChecker

Returns a new instance of Checker.



7
8
9
10
11
12
# File 'lib/sla/checker.rb', line 7

def initialize
  @max_depth = 10
  @checked_links = []
  @check_external = false
  @ignore = []
end

Instance Attribute Details

#check_externalObject

Returns the value of attribute check_external.



5
6
7
# File 'lib/sla/checker.rb', line 5

def check_external
  @check_external
end

Returns the value of attribute checked_links.



5
6
7
# File 'lib/sla/checker.rb', line 5

def checked_links
  @checked_links
end

#ignoreObject

Returns the value of attribute ignore.



5
6
7
# File 'lib/sla/checker.rb', line 5

def ignore
  @ignore
end

#max_depthObject

Returns the value of attribute max_depth.



5
6
7
# File 'lib/sla/checker.rb', line 5

def max_depth
  @max_depth
end

Instance Method Details

#check(link, depth = 1) {|link| ... } ⇒ Object

Yields:

  • (link)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sla/checker.rb', line 18

def check(link, depth=1, &block)
  link = Link.new link, depth: depth if link.is_a? String

  return if link.external? && !check_external
  ignore.each do |ignored|
    return if link.ident.start_with? ignored
  end

  link.validate
  yield link if block_given?

  return if checked_links.include? link.url

  checked_links.push link.url

  return if link.external?
  return unless link.valid?
  return if depth >= max_depth
  
  link.sublinks.each do |sublink|
    check sublink, depth+1, &block
  end
end

#countObject



14
15
16
# File 'lib/sla/checker.rb', line 14

def count
  checked_links.count
end