Class: Hootenanny::Feed::JSONFeed

Inherits:
Hootenanny::Feed show all
Defined in:
lib/hootenanny/feed/json_feed.rb

Direct Known Subclasses

DigestFeed

Constant Summary

Constants inherited from Hootenanny::Feed

FEED_TYPE_MAPPINGS

Instance Method Summary collapse

Methods inherited from Hootenanny::Feed

#+, #-, #empty?, from_content, infer, #to_digest_feed, #type

Instance Method Details

#contentObject



25
26
27
# File 'lib/hootenanny/feed/json_feed.rb', line 25

def content
  @content
end

#content=(content) ⇒ Object



29
30
31
32
33
# File 'lib/hootenanny/feed/json_feed.rb', line 29

def content=(content)
  @content = coerce_content(content)
rescue JSON::ParserError => e
  raise Hootenanny::Feed::ParseError.wrap(e)
end

#content_typeObject



13
14
15
# File 'lib/hootenanny/feed/json_feed.rb', line 13

def content_type
  'application/json'
end

#itemsObject



9
10
11
# File 'lib/hootenanny/feed/json_feed.rb', line 9

def items
  @items ||= content.fetch('items', []).map { |i| Hootenanny::Feed::JSONFeedItem.new i }
end

#to_sObject



17
18
19
20
21
22
23
# File 'lib/hootenanny/feed/json_feed.rb', line 17

def to_s
  @to_s ||= -> do
    content['items'] = items.map(&:content)

    JSON.dump(content)
  end.call
end