Module: GlobUtils
- Defined in:
- lib/globutils.rb
Constant Summary collapse
- FILE_EXT_REGEXP =
Glob Example
filenames = “/home/brian/Projects/icersplicer/bin/icersplicer,/home/brian/Projects/icersplicer/lib/version.rb,/home/brian/Projects/threatmonitor/*.rb,/home/brian/Projects/Walltime/*” files = buildfilelist(filenames)
/\/*.([a-z]|[A-Z])+$/
- FILE_WILDCARD_REGEXP =
/\*.([a-z]|[A-Z])+$/
- @@debug =
0
Instance Method Summary collapse
Instance Method Details
#buildfilelist(inputfile) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/globutils.rb', line 48 def buildfilelist(inputfile) rollfiles = Hash.new rollcounter = 0 inputfile.split(",").each {|f| puts "Filename: #{f}" if @@debug == 1 unless f =~ FILE_WILDCARD_REGEXP rollfiles.update({rollcounter => f}) rollcounter += 1 puts "Regular File" if @@debug == 1 else puts "Glob File Mask" if @@debug == 1 g = glob(f) g.each {|n| rollfiles.update({rollcounter => n[1]}) rollcounter += 1 } end } return rollfiles end |
#glob(f) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/globutils.rb', line 18 def glob(f) puts "String end: #{f[f.size - 1]}" if @@debug == 1 unless f[f.size - 1] == "*" files = Hash.new globcounter = 0 fileext = f.split(".")[f.split(".").size - 1] # Extract Extension from string for example .rb fileglob = f.gsub(FILE_EXT_REGEXP, "/**/*.#{fileext}").gsub("/*/", "/") # Match to find anything file extension / replace Glob using fileext begin # Send created glob into Dir.glob Dir.glob(fileglob) {|n| files.update({globcounter => n}) globcounter += 1 } rescue raise ArgumentError, "Invalid Glob" end return files else raise ArgumentError, "Please specify file extension for glob i.e *.html" end end |
#joinfilenames(rollfiles) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/globutils.rb', line 40 def joinfilenames(rollfiles) filenames = String.new rollfiles.each {|n| filenames << "#{n[1]}," } filenames.gsub!(%r=,$=, "") end |