Class: FlickrAggregation

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/shinmun/aggregations/flickr.rb

Overview

Example:

flickr = Flickr.new(‘www.flickr.com/services/feeds/photos_public.gne?id=40235412@N00&format=rss_200’) flickr.pics.each do |pic|

puts "#{pic.title} @ #{pic.link} updated at #{pic.date}"

end

Defined Under Namespace

Classes: Picture

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, refresh = true) ⇒ FlickrAggregation

Pass the url to the RSS feed you would like to keep tabs on by default this will request the rss from the server right away and fill the tasks array



42
43
44
45
46
# File 'lib/shinmun/aggregations/flickr.rb', line 42

def initialize(url, refresh = true)
  self.pics  = []
  self.url    = url
  self.refresh if refresh
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



23
24
25
# File 'lib/shinmun/aggregations/flickr.rb', line 23

def description
  @description
end

Returns the value of attribute link.



23
24
25
# File 'lib/shinmun/aggregations/flickr.rb', line 23

def link
  @link
end

#picsObject

Returns the value of attribute pics.



23
24
25
# File 'lib/shinmun/aggregations/flickr.rb', line 23

def pics
  @pics
end

#titleObject

Returns the value of attribute title.



23
24
25
# File 'lib/shinmun/aggregations/flickr.rb', line 23

def title
  @title
end

#urlObject

Returns the value of attribute url.



23
24
25
# File 'lib/shinmun/aggregations/flickr.rb', line 23

def url
  @url
end

Instance Method Details

#choose(num) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/shinmun/aggregations/flickr.rb', line 15

def choose(num)
  return pics unless pics.size > num
  bag = []
  set = pics.dup
  num.times {|x| bag << set.delete_at(rand(set.size))}
  bag
end

#refreshObject

This method lets you refresh the tasks int the tasks array useful if you keep the object cached in memory and



50
51
52
53
54
# File 'lib/shinmun/aggregations/flickr.rb', line 50

def refresh
  open(@url) do |http|
    parse(http.read)
  end
end