Class: Randfiles::FileList
- Inherits:
-
Object
- Object
- Randfiles::FileList
- Defined in:
- lib/randfiles/file_list.rb
Instance Method Summary collapse
-
#initialize(files, options) ⇒ FileList
constructor
A new instance of FileList.
- #select_files ⇒ Object
Constructor Details
#initialize(files, options) ⇒ FileList
Returns a new instance of FileList.
3 4 5 6 7 |
# File 'lib/randfiles/file_list.rb', line 3 def initialize(files, ) @files = files @count = .max_count || files.count @size_limit = .size_limit end |
Instance Method Details
#select_files ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/randfiles/file_list.rb', line 9 def select_files selected = [] total_size = 0 @count.times do if @files.empty? break else file = pop_random_file size = File.size(file) next if @size_limit and total_size + size > @size_limit total_size += size selected << file end end selected end |