Class: Html2rss::FeedBuilder::JsonFeed

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_builder/json_feed.rb,
lib/html2rss/feed_builder/json_feed/item.rb

Overview

Builds a JSONFeed 1.1 hash from channel metadata and articles.

Defined Under Namespace

Classes: Item

Constant Summary collapse

VERSION_URL =

Official JSON Feed 1.1 schema version URL.

'https://jsonfeed.org/version/1.1'

Instance Method Summary collapse

Constructor Details

#initialize(channel:, articles:, user_comment:, feed_url: nil) ⇒ JsonFeed

Returns a new instance of JsonFeed.

Parameters:

  • channel (Html2rss::Channel)
  • articles (Array<Html2rss::Article>)
  • user_comment (String)

    required generator comment (from Status)

  • feed_url (String, nil) (defaults to: nil)

    optional absolute self URL for the feed (JSON Feed feed_url)

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
# File 'lib/html2rss/feed_builder/json_feed.rb', line 18

def initialize(channel:, articles:, user_comment:, feed_url: nil)
  raise ArgumentError, 'user_comment must be a non-blank String' if blank_string?(user_comment)

  @channel = channel
  @articles = articles
  @feed_url = normalize_feed_url(feed_url)
  @user_comment = user_comment
end

Instance Method Details

#callHash

Builds and returns the JSONFeed hash.

Returns:

  • (Hash)

    the JSONFeed-compliant hash



31
32
33
# File 'lib/html2rss/feed_builder/json_feed.rb', line 31

def call
  base_payload.merge(authors: author_array, items: item_hashes).compact
end