Class: Qdumpfs::FileMatcher
- Inherits:
-
Object
- Object
- Qdumpfs::FileMatcher
- Defined in:
- lib/qdumpfs/option.rb
Instance Method Summary collapse
- #calc_size(size) ⇒ Object
- #exclude?(path) ⇒ Boolean
-
#initialize(options = {}) ⇒ FileMatcher
constructor
A new instance of FileMatcher.
Constructor Details
#initialize(options = {}) ⇒ FileMatcher
Returns a new instance of FileMatcher.
75 76 77 78 79 |
# File 'lib/qdumpfs/option.rb', line 75 def initialize( = {}) @patterns = [:patterns] || [] @globs = [:globs] || [] @size = calc_size([:size]) end |
Instance Method Details
#calc_size(size) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/qdumpfs/option.rb', line 81 def calc_size(size) table = { "K" => 1, "M" => 2, "G" => 3, "T" => 4, "P" => 5 } pattern = table.keys.join('') case size when nil -1 when /^(\d+)([#{pattern}]?)$/i num = Regexp.last_match[1].to_i unit = Regexp.last_match[2] num * 1024 ** (table[unit] or 0) else raise "Invalid size: #{size}" end end |
#exclude?(path) ⇒ Boolean
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/qdumpfs/option.rb', line 96 def exclude?(path) stat = File.lstat(path) if @size >= 0 and stat.file? and stat.size >= @size return true elsif @patterns.find {|pattern| pattern.match(path) } return true elsif stat.file? and @globs.find {|glob| File.fnmatch(glob, File.basename(path)) } return true end return false end |