Class: QiitaTrend::Page
- Inherits:
-
Object
- Object
- QiitaTrend::Page
- Defined in:
- lib/qiita_trend/page.rb
Overview
Qiitaのページをスクレイピングしページ情報を取得する機能を提供する
Constant Summary collapse
- QIITA_URI =
QiitaのTOPページURL
'https://qiita.com/'
- QIITA_LOGIN_URI =
QiitaのログインページURL
'https://qiita.com/login'
Instance Attribute Summary collapse
-
#cache ⇒ Cache
readonly
Cacheクラス.
-
#html ⇒ String
readonly
Qiitaページのスクレイピング結果.
-
#target ⇒ TrendType
readonly
トレンドタイプ(TrendType::DAILY,TrendType::WEEKLY,TrendType::MONTHLY).
Instance Method Summary collapse
-
#initialize(trend_type = TrendType::NORMAL, date = nil) ⇒ Page
constructor
コンストラクタ.
Constructor Details
#initialize(trend_type = TrendType::NORMAL, date = nil) ⇒ Page
コンストラクタ
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/qiita_trend/page.rb', line 26 def initialize(trend_type = TrendType::NORMAL, date = nil) @target = Target.new(trend_type, date) save_cache_directory = QiitaTrend.configuration.cache_directory.nil? ? Cache::DEFAULT_CACHE_DIRECTORY : QiitaTrend.configuration.cache_directory @cache = Cache.new(target.cache, save_cache_directory) # 指定されたキャッシュファイルが存在しない場合は処理を終了 if !date.nil? && !@cache.cached? raise Error::NotExistsCacheError, @cache end # キャッシュが存在する場合はキャッシュから取得 @html = @cache.cached? ? @cache.load_cache : create_html(@target) # キャッシュが存在しない時はキャッシュを作成する @cache.create_cache(@html) unless @cache.cached? end |
Instance Attribute Details
#cache ⇒ Cache (readonly)
Returns Cacheクラス.
13 14 15 |
# File 'lib/qiita_trend/page.rb', line 13 def cache @cache end |
#html ⇒ String (readonly)
Returns Qiitaページのスクレイピング結果.
11 12 13 |
# File 'lib/qiita_trend/page.rb', line 11 def html @html end |
#target ⇒ TrendType (readonly)
Returns トレンドタイプ(TrendType::DAILY,TrendType::WEEKLY,TrendType::MONTHLY).
9 10 11 |
# File 'lib/qiita_trend/page.rb', line 9 def target @target end |