Module: BackupOrganizer::Extensions::FileExtensions

Defined in:
lib/backup_organizer/extensions/file_extensions.rb

Instance Method Summary collapse

Instance Method Details

#ageObject



7
8
9
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 7

def age
  FileAge.new(BackupOrganizer::FileUtils.age_of(self))
end

#most_recent_in_its_day?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 19

def most_recent_in_its_day?
  mtime     = BackupOrganizer::FileUtils.mtime(self)
  midnight  = Time.local(mtime.year, mtime.month, mtime.day)
  one_day   = 24 * 60 * 60

  most_recent_in?(midnight...(midnight + one_day))
end

#most_recent_in_its_hour?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 11

def most_recent_in_its_hour?
  mtime     = BackupOrganizer::FileUtils.mtime(self)
  hour      = Time.local(mtime.year, mtime.month, mtime.day, mtime.hour)
  one_hour  = 60 * 60

  most_recent_in?(hour...(hour + one_hour))
end

#most_recent_in_its_month?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 37

def most_recent_in_its_month?
  mtime      = BackupOrganizer::FileUtils.mtime(self)
  this_month = Time.local(mtime.year, mtime.month, 1)
  mtime      = this_month + 32.days
  next_month = Time.local(mtime.year, mtime.month, 1)

  most_recent_in?(this_month...next_month)
end

#most_recent_in_its_week?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 27

def most_recent_in_its_week?
  mtime     = BackupOrganizer::FileUtils.mtime(self)
  midnight  = Time.local(mtime.year, mtime.month, mtime.day)
  one_day   = 24 * 60 * 60
  monday    = midnight - ((midnight.wday - 1) * one_day)
  monday = monday - (7 * one_day) if midnight.wday == 0

  most_recent_in?(monday...(monday + (7 * one_day)))
end

#most_recent_in_its_year?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/backup_organizer/extensions/file_extensions.rb', line 46

def most_recent_in_its_year?
  mtime     = BackupOrganizer::FileUtils.mtime(self)
  this_year = Time.local(mtime.year, 1, 1)
  next_year = Time.local(this_year.year + 1, 1, 1)

  most_recent_in?(this_year...next_year)
end