Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
発生するエラー
RSS Feed のURL: http://japanese.engadget.com/rss.xml
このエラーによって、crowlerがこのフィードのデータを取得することができていません。
この問題を調べ、修正しました。
この問題がおこるのはレアなフィードだと思うので、
メンテナンス性とシンプルさを重視した動作の挙動を提案します。
解決方法の提案
実際に利用しているfastladderの
item.category
のデータをいくつか確認したところnil
となっているデータが多くありました。多くのitemがcategory elementは存在していないことが実態のようです。
であれば、
以上を考慮して
categories methodが存在しなければ、
category
の値はnil
としてしまうというのが実運用上あまり問題にならずにcrowlもできるのではないでしょうか?却下した解決方法
初期化時に下記のようにFeedjiraで利用するパーサーの優先順位を割りあてることによって解決することができます。
ですが、この方法ですとFeedjiraのupdateによって、パーサーが増減したときに手動で対応が必要になります。そのため、あまり望ましい解決方法ではない判断しました。
--- ここから下はこれにいたる詳細な情報です。 ---
RSSの仕様を確認
以下を確認するとcategoryはoptionalなので、category element無いことも考慮して動作してよさそう。
Feedjiraの動作を確認
通常のRSSパーサーであれば categories のelementsが定義されていました
https://github.com/feedjira/feedjira/blob/master/lib/feedjira/parser/rss_entry.rb#L27
これによりelemetが、あれば最初の値、なければnilが item.category の値となる。
正しいパーサーが利用されれば category element が無いことが考慮さあれて値が返却されるように動作しているようです。
ですが、このfeedは
Feedjira::Parser::ITunesRSS
が利用されているのが問題です。Feedjiraは利用するパーサーを上記の順で検証していき
Feedjira::Parser::RSS
よりも先にFeedjira::Parser::ITunesRSS
がある。また、このRSSは
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
が記載されているからFeedjira::Parser::ITunesRSS
が利用されます。Feedjira::Parser::ITunesRSS
の category エレメントは少々特殊なようで...https://github.com/feedjira/feedjira/blob/master/lib/feedjira/parser/itunes_rss.rb#L42
_itunes_categories
となってしまっているため今回の undefined method `categories' が発生するようです。