Ruby - RSS 作成 - ファイルの更新状況を収集
- 1. 概要
- 2. モジュール
1. 概要
ファイルの更新時刻を取得するクラスです。
パス名も同時に取得しています。
パスがディレクトリであれば、ファイル名を「index.html」にしていますが、ウェブサイトの構成によって、「index.php」だったりもっと他のものも対象となる可能性があります。
現時点(2018年11月08日)では「index.html」のみになっています。
2. モジュール
=begin
コンテンツファイルの絶対パス・更新日時を取得する
=end
require('pry')
require('BaseClass')
require('ExceptLog')
class MyFile < BaseClass
@@home = ''
@@root = ''
@path = ''
@modified = ''
def initialize(home, root)
@@home = home
@@root = root
end
def Path=(uri) # パスの設定
begin
back = uri.length - @@home.length
@path = uri[-back, back]
fullpath = @@root + @path
if (FileTest.directory?(fullpath)) # コンテンツがディレクトリの場合
#puts("[#{self.class.name}.#{__method__}] fullpath=[#{fullpath}]")
if (fullpath[-1, 1] != '/') # 末尾が / でなければ / を加える
fullpath += '/'
@path += '/'
end
# コンテンツを index.html にする
fullpath += 'index.html'
@path += 'index.html'
else
end
if (!FileTest.file?(fullpath)) # コンテンツがファイルでない場合
@path = ""
@modified = ""
return
end
stat = File::Stat.new(fullpath)
#puts("[#{self.class.name}.#{__method__}] stat=[#{stat}]")
#binding.pry
@modified = stat.mtime
rescue => error
exeptlog = ExceptLog.new
exeptlog.execute(self, error)
exit 1
end
end
def PathName
return @path
end
def Modified
return @modified
end
end
|
|