Class: FeedParser::JsonFeedBuilder
- Inherits:
-
Object
- Object
- FeedParser::JsonFeedBuilder
- Includes:
- LogUtils::Logging
- Defined in:
- lib/feedparser/builder/json.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_author(h) ⇒ Object
- #build_feed(h) ⇒ Object
- #build_item(h) ⇒ Object
- #build_tag(json_tag) ⇒ Object
-
#initialize(hash) ⇒ JsonFeedBuilder
constructor
A new instance of JsonFeedBuilder.
- #to_feed ⇒ Object
Constructor Details
permalink #initialize(hash) ⇒ JsonFeedBuilder
Returns a new instance of JsonFeedBuilder.
15 16 17 |
# File 'lib/feedparser/builder/json.rb', line 15 def initialize( hash ) @feed = build_feed( hash ) end |
Class Method Details
permalink .build(hash) ⇒ Object
[View source]
10 11 12 13 |
# File 'lib/feedparser/builder/json.rb', line 10 def self.build( hash ) feed = self.new( hash ) feed.to_feed end |
Instance Method Details
permalink #build_author(h) ⇒ Object
[View source]
48 49 50 51 52 53 54 55 56 |
# File 'lib/feedparser/builder/json.rb', line 48 def ( h ) = Author.new .name = h['name'] .url = h['url'] .avatar = h['avatar'] end |
permalink #build_feed(h) ⇒ Object
[View source]
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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. << ( h['author'] ) end h['items'].each do |hash_item| feed.items << build_item( hash_item ) end feed # return new feed end |
permalink #build_item(h) ⇒ Object
[View source]
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# 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. << ( h['author'] ) end if h['tags'] h['tags'].each do |json_tag| item. << build_tag( json_tag ) end end item end |
permalink #build_tag(json_tag) ⇒ Object
[View source]
100 101 102 103 104 105 106 107 |
# 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 |
permalink #to_feed ⇒ Object
[View source]
19 20 21 |
# File 'lib/feedparser/builder/json.rb', line 19 def to_feed @feed end |