class Prune::Grouper

Assembles files into groups by month name, for archival. This is not currently a configurable behaviour (grouping by some other means, for instance.)

Public Class Methods

new( archiver ) click to toggle source
# File lib/prune/grouper.rb, line 7
def initialize( archiver )
  @groups = Hash.new{ |h,k| h[k] = [] }
  @archiver = archiver
end

Public Instance Methods

archive() click to toggle source
# File lib/prune/grouper.rb, line 22
def archive
  @groups.each_pair do |month,files|
    @archiver.archive( month, files )
  end
  sizes = @groups.values.map { |x| x.size }.join( ', ' )
  "#{@groups.size} archive(s) created (#{sizes} file(s), respectively)"
end
group( folder_name, files ) click to toggle source
# File lib/prune/grouper.rb, line 12
def group( folder_name, files )
  files.each do |file|
    mtime = File.mtime( File.join( folder_name, file ) )
    month_name = Date::ABBR_MONTHNAMES[ mtime.month ]
    group_name = "#{month_name}-#{mtime.year}"
    @groups[ group_name ] << file
  end
  return self
end