Class: MediaFeed::Feed

Inherits:
Object
  • Object
show all
Includes:
LibXML
Defined in:
lib/media_feed.rb

Overview

Mediafeeds handles the retrieval of feed information. The feed attributes are stored in feed attributes, and the individual items are stored in an array of Item objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Feed

Feed is initialized with a valid url for the feed itself.

Raises:

  • (ArgumentException)


50
51
52
53
54
55
# File 'lib/media_feed.rb', line 50

def initialize(url)
  raise ArgumentException if url.nil?
  raise InvalidUrl if url !~ /(^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]*)+. [a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
  @url = url
  @entries = nil
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



47
48
49
# File 'lib/media_feed.rb', line 47

def description
  @description
end

#itemsObject (readonly)

Returns the value of attribute items.



47
48
49
# File 'lib/media_feed.rb', line 47

def items
  @items
end

#pubDateObject (readonly)

Returns the value of attribute pubDate.



47
48
49
# File 'lib/media_feed.rb', line 47

def pubDate
  @pubDate
end

#thumbnailObject (readonly)

Returns the value of attribute thumbnail.



47
48
49
# File 'lib/media_feed.rb', line 47

def thumbnail
  @thumbnail
end

#titleObject (readonly)

Returns the value of attribute title.



47
48
49
# File 'lib/media_feed.rb', line 47

def title
  @title
end

Instance Method Details

#fetchObject

fetch the whole media feed



58
59
60
61
62
# File 'lib/media_feed.rb', line 58

def fetch
  doc = get_feed
  return nil if doc.nil?
  parse_feed(doc)
end

#fetch_since(last_date) ⇒ Object

fetch all entries of the media feed since a certain date (RFC2822 format).



65
66
67
68
# File 'lib/media_feed.rb', line 65

def fetch_since(last_date)
  @last_date = parse_date(last_date)
  fetch
end

#to_sObject



70
71
72
73
74
75
# File 'lib/media_feed.rb', line 70

def to_s
  "title #{@title}, description #{@description}" +
  @items.inject('') do |str,item|
    str + entry.to_s
  end
end