Class: Rbuzz::FeedEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rbuzz/feed_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atom_entry) ⇒ FeedEntry

Expects an Atom::Entry object



7
8
9
# File 'lib/rbuzz/feed_entry.rb', line 7

def initialize(atom_entry)
  @atom_entry = atom_entry
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



15
16
17
# File 'lib/rbuzz/feed_entry.rb', line 15

def method_missing(method, *args, &block)
  @atom_entry.send(method)
end

Instance Attribute Details

#atom_entryObject (readonly)

Returns the value of attribute atom_entry.



3
4
5
# File 'lib/rbuzz/feed_entry.rb', line 3

def atom_entry
  @atom_entry
end

#atom_repliesObject (readonly)

Returns the value of attribute atom_replies.



4
5
6
# File 'lib/rbuzz/feed_entry.rb', line 4

def atom_replies
  @atom_replies
end

Instance Method Details

#[](name) ⇒ Object



11
12
13
# File 'lib/rbuzz/feed_entry.rb', line 11

def [](name)
  @atom_entry.send(name)
end

#authorObject



48
49
50
# File 'lib/rbuzz/feed_entry.rb', line 48

def author
  @atom_entry.authors[0] if @atom_entry.respond_to?(:authors)
end

#comment_countObject



31
32
33
34
# File 'lib/rbuzz/feed_entry.rb', line 31

def comment_count
  return @comments.length if @comments
  @atom_entry["http://purl.org/syndication/thread/1.0","total"][0].to_i
end

#commentsObject



25
26
27
28
29
# File 'lib/rbuzz/feed_entry.rb', line 25

def comments
  return @comments if @comments
  fetch_comments if @atom_replies.nil?
  @comments = @atom_replies.entries.collect {|r| FeedReply.new(r) }
end

#fetch_commentsObject



19
20
21
22
23
# File 'lib/rbuzz/feed_entry.rb', line 19

def fetch_comments
  @comments = nil
  link = @atom_entry.links.find {|l| l.rel == 'replies'}
  @atom_replies = Atom::Feed.load_feed(URI.parse(link.href)) if link
end

#idObject



52
53
54
# File 'lib/rbuzz/feed_entry.rb', line 52

def id
  @atom_entry.id
end

#imagesObject



40
41
42
# File 'lib/rbuzz/feed_entry.rb', line 40

def images
  @images ||= @atom_entry.links.find_all {|l| l.type =~ /image/i }.collect {|l| l.href}.uniq
end

#urlsObject



36
37
38
# File 'lib/rbuzz/feed_entry.rb', line 36

def urls
  @links ||= @atom_entry.links.find_all {|l| l.type =~ %r{text/html}i }.collect {|l| l.href}.uniq
end

#videosObject



44
45
46
# File 'lib/rbuzz/feed_entry.rb', line 44

def videos
  @videos ||= @atom_entry.links.find_all {|l| l.type =~ %r{application/x-shockwave-flash}i }.collect {|l| l.href}.uniq
end