Class: HLS::Directory
- Inherits:
-
Object
- Object
- HLS::Directory
- Includes:
- Enumerable
- Defined in:
- lib/hls/directory.rb
Overview
Walks a source directory and yields ‘(input, relative_output_dir)` pairs for each matching file. The relative output dir drops the source’s extension so callers can join it onto a destination root.
Example:
HLS::Directory.new("uploads").glob("**/*.mp4").each do |input, output|
# input is an HLS::Input
# output is a Pathname like "course/lecture-01" (no extension)
end
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #glob(pattern) ⇒ Object
-
#initialize(source) ⇒ Directory
constructor
A new instance of Directory.
Constructor Details
#initialize(source) ⇒ Directory
Returns a new instance of Directory.
19 20 21 |
# File 'lib/hls/directory.rb', line 19 def initialize(source) @source = Pathname.new(source) end |
Instance Method Details
#each(&block) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/hls/directory.rb', line 28 def each(&block) raise ArgumentError, "call .glob(pattern) before iterating" unless @pattern @source.glob(@pattern).each do |path| relative = path.relative_path_from(@source) output = relative.dirname.join(relative.basename(path.extname)) yield Input.new(path), output end end |
#glob(pattern) ⇒ Object
23 24 25 26 |
# File 'lib/hls/directory.rb', line 23 def glob(pattern) @pattern = pattern self end |