Class: MarkdownExec::SavedFilesMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/saved_files_matcher.rb

Overview

SavedFilesMatcher

This class is responsible for matching saved files based on the given pattern. It can list all matching files, retrieve the most recent file, or a list of most recent files.

Class Method Summary collapse

Class Method Details

.list_all(folder, glob) ⇒ Object

Lists all files in the specified folder that match the given glob pattern



15
16
17
# File 'lib/saved_files_matcher.rb', line 15

def self.list_all(folder, glob)
  Dir.glob(File.join(folder, glob))
end

.most_recent(folder, glob, arr = nil) ⇒ Object

Retrieves the most recent file from the specified folder that matches the given glob pattern



20
21
22
23
24
25
# File 'lib/saved_files_matcher.rb', line 20

def self.most_recent(folder, glob, arr = nil)
  arr = list_all(folder, glob) if arr.nil?
  return if arr.count < 1

  arr.max
end

.most_recent_list(folder, glob, list_count, arr = nil) ⇒ Object

Retrieves a list of the most recent files (up to list_count) from the specified folder that match the given glob pattern



29
30
31
32
33
34
# File 'lib/saved_files_matcher.rb', line 29

def self.most_recent_list(folder, glob, list_count, arr = nil)
  arr = list_all(folder, glob) if arr.nil?
  return if arr.empty?

  arr.sort[-[arr.count, list_count].min..].reverse
end