Sha256: 988a185a8a6e09fbe34ef7b494c095fdd6b07f78a73a81e03ae59b438b3ca8fe

Contents?: true

Size: 778 Bytes

Versions: 6

Compression:

Stored size: 778 Bytes

Contents

class Dir

  def self.tags(pattern)
    files = {}
    Dir.glob(pattern).each do |file|
      tags = File.tags(file)
      files.merge!({file => tags}) unless tags.empty?
    end
    files
  end

  def self.taglob(pattern,tags)
    if(tags.include?('|'))
      Dir.tag_or(pattern,*tags.split('|'))      
    else
      Dir.tag_and(pattern,*tags.split(','))      
    end
  end

  def self.tag_and(pattern, *tags)
    tagged_files = []
    self.tags(pattern).each do |file,parsed_tags|
      tagged_files << file if (tags - parsed_tags).empty?
    end
    tagged_files
  end
  
  def self.tag_or(pattern, *tags)
    tagged_files = []
    self.tags(pattern).each do |file,parsed_tags|
      tagged_files << file if !(tags & parsed_tags).empty?
    end
    tagged_files
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
scudco-taglob-1.0.0 lib/taglob/extensions/dir.rb
scudco-taglob-1.0.1 lib/taglob/extensions/dir.rb
scudco-taglob-1.0.2 lib/taglob/extensions/dir.rb
scudco-taglob-1.1.0 lib/taglob/extensions/dir.rb
taglob-1.0.2 lib/taglob/extensions/dir.rb
taglob-1.0.0 lib/taglob/extensions/dir.rb