class Deadlink::Path
Attributes
anchor[R]
cur_file_path[R]
index[R]
link[R]
Public Class Methods
new(cur_file_path, link, index, repo_root)
click to toggle source
# File lib/deadlink/path.rb, line 7 def initialize(cur_file_path, link, index, repo_root) @cur_file_path = cur_file_path @link = link @index = index @repo_root = repo_root hash = split_link(link) @anchor = hash[:anchor] @link_file_path = hash[:filepath] @abs_link_file_path = abs_link_file_path end
Public Instance Methods
deadlink?(files)
click to toggle source
# File lib/deadlink/path.rb, line 21 def deadlink?(files) (not_exist? || anchor_invalid?(files)) && not_ignore? end
Private Instance Methods
abs_link_file_path()
click to toggle source
# File lib/deadlink/path.rb, line 44 def abs_link_file_path if specify_root?(@link_file_path) return File.join(@repo_root, @link_file_path) else return File.expand_path(@link_file_path, File.dirname(@cur_file_path)) end end
anchor_invalid?(files)
click to toggle source
# File lib/deadlink/path.rb, line 27 def anchor_invalid?(files) return false if @anchor.empty? # e.g [](#anchor) path = only_anchor? ? @cur_file_path : @abs_link_file_path file = files.find_by(path) return !file.headers.include?(@anchor) end
exist?()
click to toggle source
# File lib/deadlink/path.rb, line 40 def exist? FileTest.exist?(@abs_link_file_path) end
ignore?()
click to toggle source
# File lib/deadlink/path.rb, line 62 def ignore? url? end
not_exist?()
click to toggle source
negative wrap
# File lib/deadlink/path.rb, line 72 def not_exist? !exist? end
not_ignore?()
click to toggle source
# File lib/deadlink/path.rb, line 76 def not_ignore? !ignore? end
only_anchor?()
click to toggle source
# File lib/deadlink/path.rb, line 36 def only_anchor? @link_file_path.empty? && !@anchor.empty? end
specify_root?(path)
click to toggle source
# File lib/deadlink/path.rb, line 58 def specify_root?(path) path[0] == "/" end
split_link(link)
click to toggle source
# File lib/deadlink/path.rb, line 53 def split_link(link) # split <filenpath>#<anchor> link.match(/(?<filepath>[^#?]*)#*(?<anchor>[[^?][.]]*)/) end
url?()
click to toggle source
# File lib/deadlink/path.rb, line 66 def url? @link =~ /https?:\/\/[\S]+/ end