Class: DateNamedFile::OldDatedFile
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- DateNamedFile::OldDatedFile
- Defined in:
- lib/date_named_file/dated_file.rb
Instance Attribute Summary collapse
-
#dft ⇒ Object
(also: #template)
readonly
Returns the value of attribute dft.
-
#embedded_date ⇒ Object
readonly
Returns the value of attribute embedded_date.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(dft, filename) ⇒ OldDatedFile
constructor
A new instance of OldDatedFile.
- #inspect ⇒ Object
- #open ⇒ Object
- #pretty_inspect ⇒ Object
- #to_s ⇒ Object
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 = dft.datetime_from_filename(@path.basename.to_s) end |
Instance Attribute Details
#dft ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute embedded_date.
88 89 90 |
# File 'lib/date_named_file/dated_file.rb', line 88 def 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
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 |
#inspect ⇒ Object
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 |
#open ⇒ Object
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_inspect ⇒ Object
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_s ⇒ Object
120 121 122 |
# File 'lib/date_named_file/dated_file.rb', line 120 def to_s @path.to_s end |