Class: Dumpcar::Location
- Inherits:
-
Object
- Object
- Dumpcar::Location
- 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
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
Instance Method Summary collapse
- #dumps ⇒ Object
- #first ⇒ Object
- #from_time(time = Time.now.utc) ⇒ Object
-
#initialize(base_dir) ⇒ Location
constructor
A new instance of Location.
- #last ⇒ Object
- #next ⇒ Object
- #search(query) ⇒ Object
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_dir ⇒ Object (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
#dumps ⇒ Object
12 13 14 15 |
# File 'lib/dumpcar/location.rb', line 12 def dumps prepare_base_dir! base_dir.glob(TIMESTAMP_FILE_GLOB) end |
#first ⇒ Object
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 |
#last ⇒ Object
26 27 28 29 |
# File 'lib/dumpcar/location.rb', line 26 def last prepare_base_dir! dumps.last end |
#next ⇒ Object
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 |