Class: SnapshotSet::Snapshot

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
  extract_timestamp(name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#timeObject (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 extract_timestamp(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_sObject



38
39
40
# File 'lib/snapshot_set.rb', line 38

def to_s
  name
end