Class: Loki::FilePattern

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/loki/file_pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FilePattern

Returns a new instance of FilePattern.



7
8
9
# File 'lib/loki/file_pattern.rb', line 7

def initialize(path)
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/loki/file_pattern.rb', line 4

def path
  @path
end

Instance Method Details

#absoluteObject



46
47
48
# File 'lib/loki/file_pattern.rb', line 46

def absolute
  ::File.expand_path(@path)
end

#collection?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/loki/file_pattern.rb', line 36

def collection?
  !individual?
end

#each(&block) ⇒ Object



17
18
19
20
21
# File 'lib/loki/file_pattern.rb', line 17

def each(&block)
  Dir.glob(@path).each do |file|
    yield FilePath.new(file) if block_given?
  end
end

#individual?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/loki/file_pattern.rb', line 31

def individual?
  !(@path =~ /[\?\[\]\{\}\*]/)
end

#interpolate_each(result_pattern, &block) ⇒ Object



24
25
26
27
28
# File 'lib/loki/file_pattern.rb', line 24

def interpolate_each(result_pattern, &block)
  each do |source_path|
    yield source_path, interpolate(source_path, result_pattern) if block_given?
  end
end

#relative(from = Dir.pwd) ⇒ Object



41
42
43
# File 'lib/loki/file_pattern.rb', line 41

def relative(from = Dir.pwd)
  @path.gsub(/^#{from}\//, '')
end

#to_sObject



51
52
53
# File 'lib/loki/file_pattern.rb', line 51

def to_s
  @path.to_s
end