Class: TarsnapPruner::Archive

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

Overview

An instance of this class represents a single tarsnap backup.

We expect the name of each archive to contain an iso8601 date that represents the date that the backup was taken.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Archive

Expects the name of the archive, as given to tarsnap. It should contain an iso8601 date (e.g. 2015-05-15) that represents when the backup was taken.



14
15
16
# File 'lib/tarsnap_pruner/archive.rb', line 14

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/tarsnap_pruner/archive.rb', line 18

def name
  @name
end

Instance Method Details

#dateObject

Return a Ruby Date object for the backup’s date, or nil if one could not be discerned from the archive name.



26
27
28
# File 'lib/tarsnap_pruner/archive.rb', line 26

def date
  name =~ /.*(\d{4}-\d{2}-\d{2})/ ? Date.parse($1) : nil
end

#elapsedObject

The number of days that have elapsed since the backup date.



31
32
33
# File 'lib/tarsnap_pruner/archive.rb', line 31

def elapsed
  date ? Date.today - date : nil
end

#to_sObject



20
21
22
# File 'lib/tarsnap_pruner/archive.rb', line 20

def to_s
  name
end