Class: Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/taglob/extensions/dir.rb

Class Method Summary collapse

Class Method Details

.tag_and(pattern, *tags) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/taglob/extensions/dir.rb', line 18

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

.tag_or(pattern, *tags) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/taglob/extensions/dir.rb', line 26

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

.taglob(pattern, tags) ⇒ Object



12
13
14
15
16
# File 'lib/taglob/extensions/dir.rb', line 12

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

.tags(pattern) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/taglob/extensions/dir.rb', line 3

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