class DateNamedFile::Directory
The instantiation of a template over a specific directory. This allows us to find out which files that match the template actually exist, extract dates from them, etc.
Attributes
dir_path[RW]
@return [Pathname]
matching_files[RW]
@return [Pathname]
Public Class Methods
new(template, path)
click to toggle source
@param [DateNamedFile::Template] template The file template @param [Pathname, String] path The path to the directory
Calls superclass method
DateNamedFile::Template::new
# File lib/date_named_file/directory.rb, line 20 def initialize(template, path) @dir_path = Pathname.new(path).realdirpath raise ArgumentError.new("Directory '#{path}' does not exist") unless @dir_path.exist? raise ArgumentError.new("'#{path}' isn't a directory") unless @dir_path.directory? super((@dir_path + template.template_string).to_s) @matching_files = @dir_path.children.sort.select{|x| self.match? x.to_s}.map{|x| DatedFile.from_filename(self,x.to_s)} end
Public Instance Methods
after(date_ish)
click to toggle source
# File lib/date_named_file/directory.rb, line 45 def after(date_ish) self.select {|f| f > date_ish} end
at(date_ish)
click to toggle source
# File lib/date_named_file/directory.rb, line 30 def at(date_ish) if has_file_for_date?(date_ish) no_existence_check_at(date_ish) else MissingFile.new(self, date_ish) end end
Also aliased as: no_existence_check_at, on
each() { |f| ... }
click to toggle source
Yield matching files for each
# File lib/date_named_file/directory.rb, line 66 def each return enum_for(:each) unless block_given? @matching_files.each {|f| yield f} end
has_file_for_date?(date_ish)
click to toggle source
Does this directory have a file for the given date? @param [<anything date_ish>] date_ish (see forgiving_dateify
) @return [Boolean]
# File lib/date_named_file/directory.rb, line 57 def has_file_for_date?(date_ish) target = self.no_existence_check_at(date_ish) (@dir_path + target).exist? end
Also aliased as: has?
last()
click to toggle source
# File lib/date_named_file/directory.rb, line 49 def last @matching_files.last end
since(date_ish)
click to toggle source
# File lib/date_named_file/directory.rb, line 41 def since(date_ish) self.select {|f| f >= date_ish} end