Class: Feedjira::Parser::JSONFeed

Inherits:
Object
  • Object
show all
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

Attributes included from FeedUtilities

#etag, #last_modified, #new_entries, #updated

Class Method Summary collapse

Instance Method Summary collapse

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

#descriptionObject (readonly)

Returns the value of attribute description.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def description
  @description
end

#entriesObject (readonly)

Returns the value of attribute entries.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def entries
  @entries
end

#expiredObject (readonly)

Returns the value of attribute expired.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def expired
  @expired
end

#faviconObject (readonly)

Returns the value of attribute favicon.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def favicon
  @favicon
end

#feed_urlObject (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

#iconObject (readonly)

Returns the value of attribute icon.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def icon
  @icon
end

#jsonObject (readonly)

Returns the value of attribute json.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def json
  @json
end

#languageObject (readonly)

Returns the value of attribute language.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def language
  @language
end

#titleObject (readonly)

Returns the value of attribute title.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



18
19
20
# File 'lib/feedjira/parser/json_feed.rb', line 18

def url
  @url
end

#versionObject (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

Returns:

  • (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