Class: Loki::FilePattern
- Inherits:
-
Object
- Object
- Loki::FilePattern
- Includes:
- Enumerable
- Defined in:
- lib/loki/file_pattern.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #absolute ⇒ Object
- #collection? ⇒ Boolean
- #each(&block) ⇒ Object
- #individual? ⇒ Boolean
-
#initialize(path) ⇒ FilePattern
constructor
A new instance of FilePattern.
- #interpolate_each(result_pattern, &block) ⇒ Object
- #relative(from = Dir.pwd) ⇒ Object
- #to_s ⇒ Object
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
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/loki/file_pattern.rb', line 4 def path @path end |
Instance Method Details
#absolute ⇒ Object
46 47 48 |
# File 'lib/loki/file_pattern.rb', line 46 def absolute ::File.(@path) end |
#collection? ⇒ 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
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_s ⇒ Object
51 52 53 |
# File 'lib/loki/file_pattern.rb', line 51 def to_s @path.to_s end |