Class: DateNamedFile::OldDatedFile

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/date_named_file/dated_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dft, filename) ⇒ OldDatedFile

Returns a new instance of OldDatedFile.



91
92
93
94
95
96
# File 'lib/date_named_file/dated_file.rb', line 91

def initialize(dft, filename)
  @path = Pathname.new(filename)
  self.__setobj__ @path
  @dft = dft
  @embedded_date = dft.datetime_from_filename(@path.basename.to_s)
end

Instance Attribute Details

#dftObject (readonly) Also known as: template

Returns the value of attribute dft.



88
89
90
# File 'lib/date_named_file/dated_file.rb', line 88

def dft
  @dft
end

#embedded_dateObject (readonly)

Returns the value of attribute embedded_date.



88
89
90
# File 'lib/date_named_file/dated_file.rb', line 88

def embedded_date
  @embedded_date
end

Class Method Details

.from_date(dft, date_ish) ⇒ Object



103
104
105
# File 'lib/date_named_file/dated_file.rb', line 103

def self.from_date(dft, date_ish)
  self.new(dft, dft.filename_for(date_ish))
end

.from_filename(dft, filename) ⇒ Object

Raises:



98
99
100
101
# File 'lib/date_named_file/dated_file.rb', line 98

def self.from_filename(dft, filename)
  raise Error.new("String #{filename} does not match template '#{dft.template}'") unless dft.match? filename
  self.new(dft, filename)
end

Instance Method Details

#==(other) ⇒ Object



116
117
118
# File 'lib/date_named_file/dated_file.rb', line 116

def ==(other)
  self.basename.to_s == other.basename.to_s
end

#inspectObject



124
125
126
# File 'lib/date_named_file/dated_file.rb', line 124

def inspect
  "#<#{self.class.to_s}:#{@path} template=#{@dft.template}:#{object_id}>"
end

#openObject



107
108
109
110
111
112
113
114
# File 'lib/date_named_file/dated_file.rb', line 107

def open
  raise "File #{@path.to_s} doesn't exist" unless @path.exist?
  begin
    Zlib::GzipReader.open(@path)
  rescue Zlib::GzipFile::Error
    File.open(@path)
  end
end

#pretty_inspectObject



128
129
130
# File 'lib/date_named_file/dated_file.rb', line 128

def pretty_inspect
  "#<#{self.class.to_s}: #{@path}\n  @template=#{@dft.template}\n  @embedded_date=#{@embedded_date.to_s}\n #{object_id}>"
end

#to_sObject



120
121
122
# File 'lib/date_named_file/dated_file.rb', line 120

def to_s
  @path.to_s
end