Class: DocFace::FileTroll
- Inherits:
-
Object
- Object
- DocFace::FileTroll
- Defined in:
- lib/docface/file_troll.rb
Instance Method Summary collapse
Instance Method Details
#cleanup(h) ⇒ Object
29 30 31 32 33 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# 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) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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 |