Class: TarsnapPruner::Archive
- Inherits:
-
Object
- Object
- TarsnapPruner::Archive
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#date ⇒ Object
Return a Ruby Date object for the backup’s date, or nil if one could not be discerned from the archive name.
-
#elapsed ⇒ Object
The number of days that have elapsed since the backup date.
-
#initialize(name) ⇒ Archive
constructor
Expects the name of the archive, as given to tarsnap.
- #to_s ⇒ Object
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
#name ⇒ Object (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
#date ⇒ Object
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 |
#elapsed ⇒ Object
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_s ⇒ Object
20 21 22 |
# File 'lib/tarsnap_pruner/archive.rb', line 20 def to_s name end |