Class: SnapshotSet::Snapshot
- Inherits:
-
Object
- Object
- SnapshotSet::Snapshot
- Defined in:
- lib/snapshot_set.rb
Overview
Keeps metadata for each snapshot. Original name is stored as just name
, extracted timestamp is time
.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #extract_timestamp(name) ⇒ Object
-
#initialize(name, default_time = Time.now) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #to_s ⇒ Object
Constructor Details
#initialize(name, default_time = Time.now) ⇒ Snapshot
Returns a new instance of Snapshot.
20 21 22 23 24 |
# File 'lib/snapshot_set.rb', line 20 def initialize(name, default_time=Time.now) @time = default_time @name = name (name) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/snapshot_set.rb', line 18 def name @name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
18 19 20 |
# File 'lib/snapshot_set.rb', line 18 def time @time end |
Instance Method Details
#extract_timestamp(name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/snapshot_set.rb', line 26 def (name) if md=name.match(/(\d+)-(\d+)-(\d+)-(\d{2})(\d{2})(\d{2})(.*)/) @time = Time.parse(md.captures.join) elsif md=name.match(/(\d+)-(\d+)-(\d+)_(\d+)-(\d+)(.*)/) @time = Time.parse(md.captures.join) else @time = Time.parse(name) end rescue ArgumentError # no time information in "foobar" return nil end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/snapshot_set.rb', line 38 def to_s name end |