class Qdumpfs::FileMatcher
Public Class Methods
new(options = {})
click to toggle source
# File lib/qdumpfs/option.rb, line 67 def initialize(options = {}) @patterns = options[:patterns] || [] @globs = options[:globs] || [] @size = calc_size(options[:size]) end
Public Instance Methods
calc_size(size)
click to toggle source
# File lib/qdumpfs/option.rb, line 73 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)
click to toggle source
# File lib/qdumpfs/option.rb, line 88 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