- 1. 上下のクラストの受け渡し・再帰呼び出し
1. 上下のクラストの受け渡し・再帰呼び出し
require('pry')
require('classific')
class Check
def initialize(original)
protocol, userinfo, domain, other = URI.split(ARGV[0])
@top = "#{protocol}" + "://" + "#{domain}"
end
def execute(parent, doc, child, tree, checked)
# parent の URI の末尾を加工してインデックスまでを求める
index = parent
if (index[-1, 1] != '/') # 末尾が / でない場合は 末尾のひとつ前の / までをインデックスファイルとする
split = parent.split('/')
last = split.last
if (last.include?('.'))
index = parent[0,parent.length-last.length]
end
end
classific = Classific.new
classific.execute(parent, @top, doc, index, child, tree, checked) # リンク先を分類してチェック
puts("")
child.each_value do | value |
if ((value[:結果] != 'OK') &&
(value[:結果] != '未チェック') &&
(value[:結果] != 'nocheck'))
#binding.pry
puts(" #{value[:リンク]} ")
puts(" → #{value[:URI]} [#{value[:結果]}]")
end
end
#return; # 再帰検索しない場合はここを生かす
child.each_value do | value |
if (value[:種別][0,2] != '内部') # 内部リンクでないと検索しない
next
end
if (value[:結果] != 'OK') # OK じゃないものは既にリンク切れなので検索しない
next
end
if (value[:リンク][0,2] == '..') # .. で上位へ行くものは探さない
next
end
if (value[:URI].include?('#')) # # を含んでいるものまでは検索しない
next
end
if (index != value[:URI][0, index.length]) # インデックス部分まで一致しないものは検索しない
next
end
parent = CheckParent.new(value[:URI])
returnvalue = parent.execute(value[:URI], tree, checked)
if (returnvalue == 'unknown')
$result[value[:URI]] = { :リンク元 => index, :種別 => '不明', :リンク => value[:URI], :結果 => 'unknown' }
end
end
rescue => error
exeptlog = ExceptLog.new
binding.pry
exeptlog.execute(self, error)
exit 1
end
end
|