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.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/feedjira/parser/json_feed.rb', line 21 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.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def description @description end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def entries @entries end |
#expired ⇒ Object (readonly)
Returns the value of attribute expired.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def expired @expired end |
#favicon ⇒ Object (readonly)
Returns the value of attribute favicon.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def favicon @favicon end |
#feed_url ⇒ Object (readonly)
Returns the value of attribute feed_url.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def feed_url @feed_url end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def icon @icon end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def json @json end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def language @language end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def url @url end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
18 19 20 |
# File 'lib/feedjira/parser/json_feed.rb', line 18 def version @version end |
Class Method Details
.able_to_parse?(json) ⇒ Boolean
10 11 12 |
# File 'lib/feedjira/parser/json_feed.rb', line 10 def self.able_to_parse?(json) %r{https://jsonfeed.org/version/} =~ json end |
.parse(json) ⇒ Object
14 15 16 |
# File 'lib/feedjira/parser/json_feed.rb', line 14 def self.parse(json) new(JSON.parse(json)) end |