Class: Feedjira::Parser::JSONFeed
- Inherits:
-
Object
- Object
- Feedjira::Parser::JSONFeed
- Includes:
- FeedUtilities, SAXMachine
- Defined in:
- lib/feedjira/parser/json_feed.rb
Overview
Parser for dealing with JSON Feeds.
Constant Summary
Constants included from FeedUtilities
FeedUtilities::UPDATABLE_ATTRIBUTES
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#expired ⇒ Object
readonly
Returns the value of attribute expired.
-
#favicon ⇒ Object
readonly
Returns the value of attribute favicon.
-
#feed_url ⇒ Object
readonly
Returns the value of attribute feed_url.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Attributes included from FeedUtilities
#etag, #last_modified, #new_entries, #updated
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json) ⇒ JSONFeed
constructor
A new instance of JSONFeed.
Methods included from FeedUtilities
included, #new_entries?, #sanitize_entries!, #update_attribute, #update_from_feed, #updated?
Constructor Details
#initialize(json) ⇒ JSONFeed
Returns a new instance of JSONFeed.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/feedjira/parser/json_feed.rb', line 22 def initialize(json) @json = json @version = json.fetch("version") @title = json.fetch("title") @url = json.fetch("home_page_url", nil) @feed_url = json.fetch("feed_url", nil) @icon = json.fetch("icon", nil) @favicon = json.fetch("favicon", nil) @description = json.fetch("description", nil) @language = json.fetch("language", nil) @expired = json.fetch("expired", nil) @entries = parse_items(json["items"]) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def description @description end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def entries @entries end |
#expired ⇒ Object (readonly)
Returns the value of attribute expired.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def expired @expired end |
#favicon ⇒ Object (readonly)
Returns the value of attribute favicon.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def favicon @favicon end |
#feed_url ⇒ Object (readonly)
Returns the value of attribute feed_url.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def feed_url @feed_url end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def icon @icon end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def json @json end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def language @language end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def url @url end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
19 20 21 |
# File 'lib/feedjira/parser/json_feed.rb', line 19 def version @version end |
Class Method Details
.able_to_parse?(json) ⇒ Boolean
10 11 12 13 |
# File 'lib/feedjira/parser/json_feed.rb', line 10 def self.able_to_parse?(json) json.include?("https://jsonfeed.org/version/") || json.include?('https:\/\/jsonfeed.org\/version\/') end |
.parse(json) ⇒ Object
15 16 17 |
# File 'lib/feedjira/parser/json_feed.rb', line 15 def self.parse(json) new(JSON.parse(json)) end |