Class: Trop::FileFinder
- Inherits:
-
Object
- Object
- Trop::FileFinder
- Defined in:
- lib/trop/file_finder.rb,
lib/trop/file_finder.rb
Class Method Summary collapse
- .collect_dir_tree(path) ⇒ Object
- .collect_md_tree(path) ⇒ Object
- .collect_sorted_readme(path) ⇒ Object
Instance Method Summary collapse
- #collect_dir_tree(spath) ⇒ Object
- #collect_md_tree(spath) ⇒ Object
- #collect_readme_md_tree(spath) ⇒ Object
- #collect_sorted_readme(spath) ⇒ Object
- #dffind(_path) ⇒ Object
- #fffind(_path) ⇒ Object
- #filter_pages(pages) ⇒ Object
-
#initialize ⇒ FileFinder
constructor
A new instance of FileFinder.
Constructor Details
#initialize ⇒ FileFinder
13 14 |
# File 'lib/trop/file_finder.rb', line 13 def initialize end |
Class Method Details
.collect_dir_tree(path) ⇒ Object
145 146 147 148 |
# File 'lib/trop/file_finder.rb', line 145 def self.collect_dir_tree(path) finder = FileFinder.new finder.collect_dir_tree(path) end |
.collect_md_tree(path) ⇒ Object
140 141 142 143 |
# File 'lib/trop/file_finder.rb', line 140 def self.collect_md_tree(path) finder = FileFinder.new finder.collect_md_tree(path) end |
.collect_sorted_readme(path) ⇒ Object
135 136 137 138 |
# File 'lib/trop/file_finder.rb', line 135 def self.collect_sorted_readme(path) finder = FileFinder.new finder.collect_sorted_readme(File.(path)) end |
Instance Method Details
#collect_dir_tree(spath) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/trop/file_finder.rb', line 64 def collect_dir_tree(spath) @dirs = [] files = dffind(spath) return files end |
#collect_md_tree(spath) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/trop/file_finder.rb', line 111 def collect_md_tree(spath) @mds = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('.MD') puts "Found : #{page.to_path}".cyan if $DEBUG @mds << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @mds end |
#collect_readme_md_tree(spath) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/trop/file_finder.rb', line 93 def collect_readme_md_tree(spath) @readmes = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('README') && fbase.include?('.MD') puts "Found : #{page.to_path}".cyan if $DEBUG @readmes << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @readmes end |
#collect_sorted_readme(spath) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trop/file_finder.rb', line 72 def collect_sorted_readme(spath) @readmes = [] files = fffind(spath) files.each do |page| page = Pathname.new(page) next if page.directory? fbase = page.basename.to_s.upcase if page.file? && fbase.include?('README') ##&& fbase.include?('.MD') puts "Found : #{page.to_path}".red if Sh.verbose? @readmes << page.to_s else Sh.info "skip: #{page.to_path}".blue if $DEBUG end end @readmes = @readmes.sort @readmes = @readmes.uniq res1, res2, res3 = filter_pages(@readmes) return res1, res2, res3 end |
#dffind(_path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trop/file_finder.rb', line 30 def dffind(_path) _path = Dir.getwd.to_s if _path.equal?('.') _path = File.(_path) @path = _path rule = FileFind.new( :ftype => 'directory', :follow => true, :path => _path.to_s ) tree = rule.find tree end |
#fffind(_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trop/file_finder.rb', line 16 def fffind(_path) _path = Dir.getwd.to_s if _path.equal?('.') _path = File.(_path) @path = _path rule = FileFind.new( :ftype => 'file', :follow => true, :path => _path.to_s ) tree = rule.find tree end |
#filter_pages(pages) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/trop/file_finder.rb', line 44 def filter_pages(pages) tops = [] generics = [] contents = [] pages.each do |p| if p.start_with?(File.join(@path, 'doc/README.md')) tops << p elsif p.start_with?(File.join(@path, 'generic/doc/README.md')) tops << p elsif p.start_with?(File.join(@path, 'doc/')) tops << p elsif p.start_with?(File.join(@path, 'generic/')) generics << p else contents << p end end return tops, generics, contents end |