Class: Lotus::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/feed.rb

Overview

This class represents a Lotus::Feed object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Feed

Creates a new representation of a feed.

options:

id            => 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 Lotus::Author's for this feed.
                 Defaults: []
contributors  => The list of Lotus::Author's that contributed to this
                 feed. Defaults: []
entries       => The list of Lotus::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 Lotus::Category's that describe how to
                 categorize and describe the content of the feed.
                 Defaults: []
rights        => A String depicting the rights of entries 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 Lotus::Link that adds relations to other
                 resources.
generator     => A Lotus::Generator representing the agent
                 responsible for generating this feed.

Usage:

author = Lotus::Author.new(:name => "Kelly")

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


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/lotus/feed.rb', line 120

def initialize(options = {})
  @id = options[:id]
  @url = options[:url]
  @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] || []
  @entries = options[:entries] || []
  @updated = options[:updated]
  @published = options[:published]
  @salmon_url = options[:salmon_url]
  @hubs = options[:hubs] || []
  @generator = options[:generator]
end

Instance Attribute Details

#authorsObject (readonly)

Holds the list of authors as Lotus::Author responsible for this feed.



58
59
60
# File 'lib/lotus/feed.rb', line 58

def authors
  @authors
end

#categoriesObject (readonly)

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



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

def categories
  @categories
end

#contributorsObject (readonly)

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



49
50
51
# File 'lib/lotus/feed.rb', line 49

def contributors
  @contributors
end

#entriesObject (readonly)

Holds the list of entries as Lotus::Activity contained within this feed.



61
62
63
# File 'lib/lotus/feed.rb', line 61

def entries
  @entries
end

#generatorObject (readonly)

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



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

def generator
  @generator
end

#hubsObject (readonly)

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



65
66
67
# File 'lib/lotus/feed.rb', line 65

def hubs
  @hubs
end

#iconObject (readonly)

Holds the URL for the icon representing this feed.



39
40
41
# File 'lib/lotus/feed.rb', line 39

def icon
  @icon
end

#idObject (readonly)

Holds the id that uniquely represents this feed.



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

def id
  @id
end

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



71
72
73
# File 'lib/lotus/feed.rb', line 71

def links
  @links
end

#logoObject (readonly)

Holds the URL for the logo representing this feed.



42
43
44
# File 'lib/lotus/feed.rb', line 42

def 
  @logo
end

#publishedObject (readonly)

Holds the DateTime when this feed was originally created.



52
53
54
# File 'lib/lotus/feed.rb', line 52

def published
  @published
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.



24
25
26
# File 'lib/lotus/feed.rb', line 24

def rights
  @rights
end

#salmon_urlObject (readonly)

Holds the salmon url that handles notifications for this feed.



68
69
70
# File 'lib/lotus/feed.rb', line 68

def salmon_url
  @salmon_url
end

#subtitleObject (readonly)

Holds the subtitle for this feed.



33
34
35
# File 'lib/lotus/feed.rb', line 33

def subtitle
  @subtitle
end

#subtitle_typeObject (readonly)

Holds the content-type for the subtitle.



36
37
38
# File 'lib/lotus/feed.rb', line 36

def subtitle_type
  @subtitle_type
end

#titleObject (readonly)

Holds the title for this feed.



27
28
29
# File 'lib/lotus/feed.rb', line 27

def title
  @title
end

#title_typeObject (readonly)

Holds the content-type for the title.



30
31
32
# File 'lib/lotus/feed.rb', line 30

def title_type
  @title_type
end

#updatedObject (readonly)

Holds the DateTime when this feed was last modified.



55
56
57
# File 'lib/lotus/feed.rb', line 55

def updated
  @updated
end

#urlObject (readonly)

Holds the url that represents this feed.



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

def url
  @url
end

Instance Method Details

#to_atomObject

Returns a string containing an Atom representation of the feed.



184
185
186
187
188
# File 'lib/lotus/feed.rb', line 184

def to_atom
  require 'lotus/atom/feed'

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

#to_hashObject

Returns a hash of the properties of the feed.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/lotus/feed.rb', line 160

def to_hash
  {
    :id => self.id,
    :url => self.url,
    :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,
    :entries => self.entries.dup,
    :updated => self.updated,
    :salmon_url => self.salmon_url,
    :published => self.published,
    :generator => self.generator
  }
end

Yields a Lotus::Link to this feed.

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

Usage:

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

Generates a link with:

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


152
153
154
155
156
157
# File 'lib/lotus/feed.rb', line 152

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

  Lotus::Link.new(options)
end