class Deadlink::MdFile
Attributes
headers[R]
link_paths[R]
path[R]
Public Class Methods
new(file_path, repo_root)
click to toggle source
# File lib/deadlink/md_file.rb, line 6 def initialize(file_path, repo_root) @path = file_path @headers = [] @link_paths = [] attribute(repo_root) end
Private Instance Methods
attribute(repo_root)
click to toggle source
# File lib/deadlink/md_file.rb, line 15 def attribute(repo_root) File.open(@path) do |f| prev_line = nil f.each_with_index do |line,index| sharp_header(line) { |header| @headers.push header } under_line_header(line, prev_line) { |header| @headers.push header }; prev_line = line link(line, index, repo_root) { |path| @link_paths.push path } end end end
link(line, index, repo_root) { |path(path, rstrip, index + 1, repo_root)| ... }
click to toggle source
# File lib/deadlink/md_file.rb, line 39 def link(line, index, repo_root) line.scan link_pattern do |link| # capthure links path part yield Path.new(@path, link[0].rstrip, index + 1, repo_root) end end
link_pattern()
click to toggle source
# File lib/deadlink/md_file.rb, line 53 def link_pattern /\[[^\]]*\]\((?<link>[^)]+)\)/ end
sharp_header(line) { |gsub(" ", "-")| ... }
click to toggle source
# File lib/deadlink/md_file.rb, line 26 def sharp_header(line) if line =~ sharp_header_pattern # capture sharp header part header = Regexp.last_match[:header].downcase.rstrip yield header.gsub(" ", "-") end end
sharp_header_pattern()
click to toggle source
# File lib/deadlink/md_file.rb, line 45 def sharp_header_pattern /^\#{1,6} +(?<header>.+)/ end
under_header_pattern()
click to toggle source
# File lib/deadlink/md_file.rb, line 49 def under_header_pattern /^[-]+$|^[=]+$/ end
under_line_header(line, prev_line) { |chomp.gsub(" ", "-")| ... }
click to toggle source
# File lib/deadlink/md_file.rb, line 33 def under_line_header(line, prev_line) if line =~ under_header_pattern && !prev_line.nil? yield prev_line.chomp.downcase.gsub(" ", "-") end end