Class: ElibMgmt::Cli::FileFilter
- Inherits:
-
Object
- Object
- ElibMgmt::Cli::FileFilter
- Includes:
- TR::CondUtils
- Defined in:
- lib/elib_mgmt/cli/file_filter.rb
Constant Summary collapse
- SPat =
"[-,_,.,\\s]"- SPat2 =
"[\(,\),-,_,.,\\s]"- SPatL =
"[\(,-,_,.,\\s]"- SPatR =
"[\),-,_,.,\\s]"
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
Instance Method Summary collapse
- #filter(name, pattern = "**/**", opts = {}) ⇒ Object
-
#initialize(base) ⇒ FileFilter
constructor
A new instance of FileFilter.
Constructor Details
#initialize(base) ⇒ FileFilter
Returns a new instance of FileFilter.
16 17 18 19 20 |
# File 'lib/elib_mgmt/cli/file_filter.rb', line 16 def initialize(base) @base_path = base @logger = TeLogger::Tlogger.new(STDOUT) @logger.tag = :ffilter end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
15 16 17 |
# File 'lib/elib_mgmt/cli/file_filter.rb', line 15 def base_path @base_path end |
Instance Method Details
#filter(name, pattern = "**/**", opts = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/elib_mgmt/cli/file_filter.rb', line 22 def filter(name, pattern = "**/**", opts = {}) if is_empty?(name) [] else spec = [] #if name.include?("*") # found = Dir.glob(File.join(@base_path, pattern)).reject { |f| File.directory?(f) }.select { |v| # vv = File.basename(v, File.extname(v)).downcase # spec = name.downcase.gsub("*","\\w*") # # beginning # # exact match # vv =~ /^#{spec}\z/i or # # match starting with keyword # vv =~ /^#{spec}[-,.,_,\s]/i or # # middle # vv =~ /[-,.,_,|,\s,\W]#{spec}[-,.,_,|,\s,\W]/i or # #vv =~ /[-,.,_,\s]#{spec}[-,.,_,\s]/i or # # ending # vv =~ /[-,.,_,\s]#{spec}\z/i or # vv =~ /[-,.,_,\s,\[,\(]#{spec}[\],\)]/i # #vv =~ /[-,.,_,\s]#{spec}\z/i # } #elsif name.include?(" ") if name.include?(" ") pname = name.split(" ").map { |v| "#{v.downcase}" } spec = pname.join("[-,.,_,|,\s,\W]") found = Dir.glob(File.join(@base_path, pattern)).reject { |f| File.directory?(f) }.select { |v| vv = File.basename(v, File.extname(v)).downcase # beginning # exact match vv =~ /^#{spec}\z/i or # match starting with keyword vv =~ /^#{spec}[-,.,_,\s\W]/i or # middle vv =~ /[-,.,_,|,\s,\W]#{spec}[-,.,_,|,\s,\W]/i or #vv =~ /[-,.,_,\s]#{spec}[-,.,_,\s]/i or # ending vv =~ /[-,.,_,\s]#{spec}\z/i or #vv =~ /[-,.,_,\s,\[,\(]#{spec}[\],\)]/i vv =~ /[-,.,_,|,\s,\W]#{spec}[-,.,_,|,\s,\W]\z/i } else # single word found = Dir.glob(File.join(@base_path, pattern)).reject { |f| File.directory?(f) }.select { |v| spec = name.downcase vv = File.basename(v, File.extname(v)).downcase # beginning # exact match vv =~ /^#{spec}\z/i or # match starting with keyword vv =~ /^#{spec}[-,.,_,\s,\W]/i or # middle vv =~ /[-,.,_,|,\s,\W]#{spec}[-,.,_,|,\s,\W]/i or #vv =~ /[-,.,_,\s]#{name}[-,.,_,\s]/i or # ending vv =~ /[-,.,_,\s,\W]#{spec}\z/i or #vv =~ /[-,.,_,\s,\[,\(]#{name}[\],\)]/i vv =~ /[-,.,_,|,\s,\W]#{spec}[-,.,_,|,\s,\W]\z/i } end found end end |