class DocFace::FileTroll

Public Instance Methods

cleanup(h) click to toggle source
# File lib/docface/file_troll.rb, line 29
def cleanup(h)
  return true if h.empty?
  h.find_all{|k,v|h[k]=nil if v.is_a?(Hash)&&cleanup(v)}
  false
end
index_hash(list) click to toggle source
# File lib/docface/file_troll.rb, line 18
def index_hash(list)
  tree = Hash.new
  list.sort.each do |w|
    h = tree
    w.split('/').each do |part|
      h = h[part] ||= Hash.new
    end
  end
  tree
end
troll(dir) click to toggle source
# File lib/docface/file_troll.rb, line 4
def troll(dir)
  if File.directory?(dir)
    index = Array.new
    path = dir.gsub(/\\(?=\S)/, '/')
    Dir.glob(File.join(path, '**/*.{md,MD,markdown,mdown}')).each do |file|
      index << file
    end
    index
  else
    puts "The directory #{dir} does not exist."
    exit
  end
end