class FeedParser::JsonFeedBuilder
Public Class Methods
build( hash )
click to toggle source
# File lib/feedparser/builder/json.rb, line 10 def self.build( hash ) feed = self.new( hash ) feed.to_feed end
new( hash )
click to toggle source
# File lib/feedparser/builder/json.rb, line 15 def initialize( hash ) @feed = build_feed( hash ) end
Public Instance Methods
build_feed( h )
click to toggle source
# File lib/feedparser/builder/json.rb, line 25 def build_feed( h ) feed = Feed.new feed.format = 'json' feed.title = h['title'] feed.url = h['home_page_url'] feed.feed_url = h['feed_url'] feed.summary = h['description'] if h['author'] feed.authors << build_author( h['author'] ) end h['items'].each do |hash_item| feed.items << build_item( hash_item ) end feed # return new feed end
build_item( h )
click to toggle source
# File lib/feedparser/builder/json.rb, line 60 def build_item( h ) item = Item.new # Item.new item.guid = h['id'] item.title = h['title'] item.url = h['url'] item.external_url = h['external_url'] ## convert date if present (from string to date type) date_published_str = h['date_published'] if date_published_str item.published_local = DateTime.iso8601( date_published_str ) item.published = item.published_local.utc end date_modified_str = h['date_modified'] if date_modified_str item.updated_local = DateTime.iso8601( date_modified_str ) item.updated = item.updated_local.utc end item.content_html = h['content_html'] item.content_text = h['content_text'] item.summary = h['summary'] if h['author'] item.authors << build_author( h['author'] ) end if h['tags'] h['tags'].each do |json_tag| item.tags << build_tag( json_tag ) end end item end
build_tag( json_tag )
click to toggle source
# File lib/feedparser/builder/json.rb, line 100 def build_tag( json_tag ) ## pp rss_cat tag = Tag.new tag.name = json_tag tag end
to_feed()
click to toggle source
# File lib/feedparser/builder/json.rb, line 19 def to_feed @feed end