class Feedjira::Parser::JSONFeedItem

Parser for dealing with JSON Feed items.

Attributes

author[R]
banner_image[R]
categories[R]
content[R]
entry_id[R]
external_url[R]
image[R]
json[R]
published[R]
summary[R]
title[R]
updated[R]
url[R]

Public Class Methods

new(json) click to toggle source
# File lib/feedjira/parser/json_feed_item.rb, line 12
def initialize(json)
  @json = json
  @entry_id = json.fetch("id")
  @url = json.fetch("url")
  @external_url = json.fetch("external_url", nil)
  @title = json.fetch("title", nil)
  @content = parse_content(json.fetch("content_html", nil), json.fetch("content_text", nil))
  @summary = json.fetch("summary", nil)
  @image = json.fetch("image", nil)
  @banner_image = json.fetch("banner_image", nil)
  @published = parse_published(json.fetch("date_published", nil))
  @updated = parse_updated(json.fetch("date_modified", nil))
  @author = author_name(json.fetch("author", nil))
  @categories = json.fetch("tags", [])
end

Private Instance Methods

author_name(author_obj) click to toggle source
# File lib/feedjira/parser/json_feed_item.rb, line 50
def author_name(author_obj)
  return nil if author_obj.nil?

  author_obj["name"]
end
parse_content(content_html, content_text) click to toggle source

Convenience method to return the included content type. Prefer content_html unless it isn’t included.

# File lib/feedjira/parser/json_feed_item.rb, line 44
def parse_content(content_html, content_text)
  return content_html unless content_html.nil?

  content_text
end
parse_published(date_published) click to toggle source
# File lib/feedjira/parser/json_feed_item.rb, line 30
def parse_published(date_published)
  return nil unless date_published

  Time.parse_safely(date_published)
end
parse_updated(date_modified) click to toggle source
# File lib/feedjira/parser/json_feed_item.rb, line 36
def parse_updated(date_modified)
  return nil unless date_modified

  Time.parse_safely(date_modified)
end