Class: Html2rss::FeedResult
- Inherits:
-
Object
- Object
- Html2rss::FeedResult
- Defined in:
- lib/html2rss/feed_result.rb
Overview
Gem contract: instances must round-trip through Marshal.dump / Marshal.load
so web can cache one scrape and render RSS or JSON Feed on read. Loaded results
are re-frozen via private #marshal_load. For trusted cache reads only,
Marshal.load(payload, freeze: true) is also safe.
Closed Marshal-cacheable handle for one scrape.
Frozen consumer query/render set (do not grow without an explicit contract change): #empty?, #channel_title, #to_rss, #to_json_feed, and #status.
Non-goals: no Channel reader, no Articles reader, no peephole into scrape internals. html2rss-web and other consumers must use only this surface.
Instance Attribute Summary collapse
-
#status ⇒ Html2rss::Status
readonly
Frozen scraper tallies, dedup count, and generator formatter.
Instance Method Summary collapse
-
#channel_title ⇒ String
Channel title string only — does not expose the channel object.
-
#empty? ⇒ Boolean
True when the scrape produced no items.
-
#initialize(channel:, articles:, status:, stylesheets: []) ⇒ FeedResult
constructor
A new instance of FeedResult.
-
#to_json_feed(feed_url: nil) ⇒ Hash
JSON Feed 1.1 hash.
-
#to_rss ⇒ RSS::Rss
RSS 2.0 document.
Constructor Details
#initialize(channel:, articles:, status:, stylesheets: []) ⇒ FeedResult
Returns a new instance of FeedResult.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/html2rss/feed_result.rb', line 23 def initialize(channel:, articles:, status:, stylesheets: []) raise ArgumentError, 'channel must be a Html2rss::Channel' unless channel.is_a?(Channel) raise ArgumentError, 'status must be a Html2rss::Status' unless status.is_a?(Status) articles = Array(articles) raise ArgumentError, 'articles must all be Html2rss::Article' unless articles.all?(Article) @channel = channel @articles = articles.dup.freeze @status = status @stylesheets = freeze_stylesheets(stylesheets) freeze end |
Instance Attribute Details
#status ⇒ Html2rss::Status (readonly)
Returns frozen scraper tallies, dedup count, and generator formatter.
#to_h on status is a stable consumer contract for observability payloads.
73 74 75 |
# File 'lib/html2rss/feed_result.rb', line 73 def status @status end |
Instance Method Details
#channel_title ⇒ String
Channel title string only — does not expose the channel object.
45 |
# File 'lib/html2rss/feed_result.rb', line 45 def channel_title = @channel.title |
#empty? ⇒ Boolean
Returns true when the scrape produced no items.
39 |
# File 'lib/html2rss/feed_result.rb', line 39 def empty? = @articles.empty? |
#to_json_feed(feed_url: nil) ⇒ Hash
Returns JSON Feed 1.1 hash.
61 62 63 64 65 66 67 68 |
# File 'lib/html2rss/feed_result.rb', line 61 def to_json_feed(feed_url: nil) FeedBuilder::JsonFeed.new( channel: @channel, articles: @articles, feed_url:, user_comment: status.to_generator_comment ).call end |
#to_rss ⇒ RSS::Rss
Returns RSS 2.0 document.
49 50 51 52 53 54 55 56 |
# File 'lib/html2rss/feed_result.rb', line 49 def to_rss FeedBuilder::Rss.new( channel: @channel, articles: @articles, stylesheets: @stylesheets, generator: status.to_generator_comment ).call end |