Class: Nelumba::Feed

Inherits:
Collection show all
Defined in:
lib/nelumba/feed.rb

Overview

This class represents a Nelumba::Feed object.

Constant Summary

Constants included from Object

Object::USERNAME_REGULAR_EXPRESSION

Instance Attribute Summary collapse

Attributes inherited from Collection

#items, #total_items

Attributes included from Object

#author, #content, #display_name, #html, #image, #published, #summary, #text, #uid, #updated, #url

Instance Method Summary collapse

Methods included from Object

#mentions, #reply_to, #to_as1, #to_html, #to_json, #to_text

Constructor Details

#initialize(options = {}, &blk) ⇒ Feed

Creates a new representation of a feed.

options:

uid           => The unique identifier for this feed.
url           => The url that represents this feed.
title         => The title for this feed. Defaults: "Untitled"
title_type    => The content type for the title.
subtitle      => The subtitle for this feed.
subtitle_type => The content type for the subtitle.
authors       => The list of Nelumba::Person's for this feed.
                 Defaults: []
contributors  => The list of Nelumba::Person's that contributed to this
                 feed. Defaults: []
items         => The list of Nelumba::Activity's for this feed.
                 Defaults: []
icon          => The url of the icon that represents this feed. It
                 should have an aspect ratio of 1 horizontal to 1
                 vertical and optimized for presentation at a
                 small size.
logo          => The url of the logo that represents this feed. It
                 should have an aspect ratio of 2 horizontal to 1
                 vertical.
categories    => An array of Nelumba::Category's that describe how to
                 categorize and describe the content of the feed.
                 Defaults: []
rights        => A String depicting the rights of items without
                 explicit rights of their own. SHOULD NOT be machine
                 interpreted.
updated       => The DateTime representing when this feed was last
                 modified.
published     => The DateTime representing when this feed was originally
                 published.
salmon_url    => The url of the salmon endpoint, if one exists, for this
                 feed.
links         => An array of Nelumba::Link that adds relations to other
                 resources.
generator     => A Nelumba::Generator representing the agent
                 responsible for generating this feed.

Usage:

author = Nelumba::Person.new(:name => "Kelly")

feed = Nelumba::Feed.new(:title     => "My Feed",
                         :uid     => "1",
                         :url     => "http://example.com/feeds/1",
                         :authors => [author])


100
101
102
# File 'lib/nelumba/feed.rb', line 100

def initialize(options = {}, &blk)
  init(options, &blk)
end

Instance Attribute Details

#authorsObject (readonly)

Holds the list of authors as Nelumba::Person responsible for this feed.



41
42
43
# File 'lib/nelumba/feed.rb', line 41

def authors
  @authors
end

#categoriesObject (readonly)

Holds the list of categories for this feed as Nelumba::Category.



8
9
10
# File 'lib/nelumba/feed.rb', line 8

def categories
  @categories
end

#contributorsObject (readonly)

Holds the list of contributors, if any, that are involved in this feed as Nelumba::Person.



38
39
40
# File 'lib/nelumba/feed.rb', line 38

def contributors
  @contributors
end

#generatorObject (readonly)

Holds the generator for this content as an Nelumba::Generator.



34
35
36
# File 'lib/nelumba/feed.rb', line 34

def generator
  @generator
end

#hubsObject (readonly)

Holds the list of hubs that are available to manage subscriptions to this feed.



45
46
47
# File 'lib/nelumba/feed.rb', line 45

def hubs
  @hubs
end

#iconObject (readonly)

Holds the URL for the icon representing this feed.



28
29
30
# File 'lib/nelumba/feed.rb', line 28

def icon
  @icon
end

Holds links to other resources as an array of Nelumba::Link



51
52
53
# File 'lib/nelumba/feed.rb', line 51

def links
  @links
end

#logoObject (readonly)

Holds the URL for the logo representing this feed.



31
32
33
# File 'lib/nelumba/feed.rb', line 31

def 
  @logo
end

#rightsObject (readonly)

Holds human-readable information about the content rights of the entries in the feed without an explicit rights field of their own. SHOULD NOT be machine interpreted.



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

def rights
  @rights
end

#salmon_urlObject (readonly)

Holds the salmon url that handles notifications for this feed.



48
49
50
# File 'lib/nelumba/feed.rb', line 48

def salmon_url
  @salmon_url
end

#subtitleObject (readonly)

Holds the subtitle for this feed.



22
23
24
# File 'lib/nelumba/feed.rb', line 22

def subtitle
  @subtitle
end

#subtitle_typeObject (readonly)

Holds the content-type for the subtitle.



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

def subtitle_type
  @subtitle_type
end

#titleObject (readonly)

Holds the title for this feed.



16
17
18
# File 'lib/nelumba/feed.rb', line 16

def title
  @title
end

#title_typeObject (readonly)

Holds the content-type for the title.



19
20
21
# File 'lib/nelumba/feed.rb', line 19

def title_type
  @title_type
end

Instance Method Details

#init(options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/nelumba/feed.rb', line 104

def init(options = {})
  super options

  @icon = options[:icon]
  @logo = options[:logo]
  @rights = options[:rights]
  @title = options[:title] || "Untitled"
  @title_type = options[:title_type]
  @subtitle = options[:subtitle]
  @subtitle_type = options[:subtitle_type]
  @authors = options[:authors] || []
  @categories = options[:categories] || []
  @contributors = options[:contributors] || []
  @salmon_url = options[:salmon_url]
  @hubs = options[:hubs] || []
  @generator = options[:generator]
end

#to_atomObject

Returns a string containing an Atom representation of the feed.



167
168
169
170
171
# File 'lib/nelumba/feed.rb', line 167

def to_atom
  require 'nelumba/atom/feed'

  Nelumba::Atom::Feed.from_canonical(self).to_xml
end

#to_hashObject

Returns a hash of the properties of the feed.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/nelumba/feed.rb', line 141

def to_hash
  {
    :hubs => (self.hubs || []).dup,
    :icon => self.icon,
    :logo => self.,
    :rights => self.rights,
    :title => self.title,
    :title_type => self.title_type,
    :subtitle => self.subtitle,
    :subtitle_type => self.subtitle_type,
    :authors => (self.authors || []).dup,
    :categories => (self.categories || []).dup,
    :contributors => (self.contributors || []).dup,
    :updated => self.updated,
    :salmon_url => self.salmon_url,
    :published => self.published,
    :generator => self.generator
  }.merge(super)
end

#to_json_hashObject



161
162
163
164
# File 'lib/nelumba/feed.rb', line 161

def to_json_hash
  {
  }.merge(super)
end

Yields a Nelumba::Link to this feed.

options: Can override Nelumba::Link properties, such as rel.

Usage:

feed = Nelumba::Feed.new(:title => "Foo", :url => "http://example.com")
feed.to_link(:rel => "alternate", :title => "Foo's Feed")

Generates a link with:

<Nelumba::Link rel="alternate" title="Foo's Feed" url="http://example.com">


133
134
135
136
137
138
# File 'lib/nelumba/feed.rb', line 133

def to_link(options = {})
  options = { :title => self.title,
              :href  => self.url }.merge(options)

  Nelumba::Link.new(options)
end