Class: Ferver::FileList
- Inherits:
-
Object
- Object
- Ferver::FileList
- Includes:
- Enumerable
- Defined in:
- lib/ferver/file_list.rb
Overview
A representation of Ferver’s file list
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#file_by_id(id) ⇒ Object
Fetch a file by its index An id out of range with raise FileNotFoundError.
-
#initialize(files) ⇒ FileList
constructor
Create a new instance with given directory.
- #size ⇒ Object
Constructor Details
#initialize(files) ⇒ FileList
Create a new instance with given directory
9 10 11 |
# File 'lib/ferver/file_list.rb', line 9 def initialize(files) @files = files.sort_by { |f| f.name.downcase } end |
Instance Method Details
#each(&block) ⇒ Object
13 14 15 |
# File 'lib/ferver/file_list.rb', line 13 def each(&block) @files.each(&block) end |
#file_by_id(id) ⇒ Object
Fetch a file by its index An id out of range with raise FileNotFoundError
24 25 26 |
# File 'lib/ferver/file_list.rb', line 24 def file_by_id(id) @files.at(id) || raise(FileNotFoundError, "File id=#{id} not found") end |
#size ⇒ Object
17 18 19 |
# File 'lib/ferver/file_list.rb', line 17 def size @files.size end |