Class: Dumpcar::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/dumpcar/location.rb

Constant Summary collapse

TIMESTAMP_STRFTIME_FORMAT =
"%Y%m%d%H%M%S"
TIMESTAMP_GLOB =
14.times.map { "[0-9]" }.join
TIMESTAMP_FILE_GLOB =
TIMESTAMP_GLOB + "*.dump"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ Location

Returns a new instance of Location.



8
9
10
# File 'lib/dumpcar/location.rb', line 8

def initialize(base_dir)
  @base_dir = Pathname.new base_dir
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



7
8
9
# File 'lib/dumpcar/location.rb', line 7

def base_dir
  @base_dir
end

Instance Method Details

#dumpsObject



12
13
14
15
# File 'lib/dumpcar/location.rb', line 12

def dumps
  prepare_base_dir!
  base_dir.glob(TIMESTAMP_FILE_GLOB)
end

#firstObject



17
18
19
20
# File 'lib/dumpcar/location.rb', line 17

def first
  prepare_base_dir!
  dumps.first
end

#from_time(time = Time.now.utc) ⇒ Object



36
37
38
# File 'lib/dumpcar/location.rb', line 36

def from_time(time = Time.now.utc)
  time.strftime(TIMESTAMP_STRFTIME_FORMAT)
end

#lastObject



26
27
28
29
# File 'lib/dumpcar/location.rb', line 26

def last
  prepare_base_dir!
  dumps.last
end

#nextObject



31
32
33
34
# File 'lib/dumpcar/location.rb', line 31

def next
  prepare_base_dir!
  base_dir.join(from_time + ".dump").to_s
end

#search(query) ⇒ Object



22
23
24
# File 'lib/dumpcar/location.rb', line 22

def search(query)
  dumps.first { |file| file.basename.starts_with(query) }
end