Ruby - RSS 作成 - コンテンツ情報を生成
- 1. 概要
- 2. モジュール
1. 概要
コンテンツテーブルの情報を生成します。
2. モジュール
=begin
コンテンツの生ファイルの更新状況を取得する
uri, ドキュメントの中身を元に
実際のファイルを割り出し
コンテンツテーブルのレコードを作成する
レコードは以下の通り
index インデックス番号
uri
document コンテンツの相対パス+ファイル名
title タイトル
modified 更新日時
description コンテンツの要約
content コンテンツの内容
=end
require('pry')
require('ExceptLog')
require('MyFile')
class Contents < BaseClass
@@myfeed = Hash.new
@@detail = Array.new
def initialize
end
def feed=(dbfeed)
@@myfeed = dbfeed
end
def get(uri, doc)
begin
#puts("[#{self.class.name}.#{__method__}] uri=[#{uri}]")
contents = Hash.new
contents[:index] = @@myfeed['index']
contents[:uri] = uri
# doc から取得する項目
contents[:title] = doc.title
contents[:description] = doc.title # 要約は当面タイトルを適用
doc.search('script').remove
contents[:content] = doc.css('body').text
# 連続する改行とタブは1つにする
contents[:content].squeeze!("\n")
contents[:content].squeeze!("\t")
# file から割り出す内容
file = MyFile.new(@@myfeed['home'], @@myfeed['root'])
file.Path = uri
contents[:document] = file.PathName
contents[:modified] = file.Modified
@@detail.push(contents)
rescue => error
exeptlog = ExceptLog.new
exeptlog.execute(self, error)
exit 1
end
end
def detail
return @@detail
end
end
|
|