Class: FlickrAggregation
- Inherits:
-
Object
- Object
- FlickrAggregation
- 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
-
#description ⇒ Object
Returns the value of attribute description.
-
#link ⇒ Object
Returns the value of attribute link.
-
#pics ⇒ Object
Returns the value of attribute pics.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #choose(num) ⇒ Object
-
#initialize(url, refresh = true) ⇒ FlickrAggregation
constructor
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.
-
#refresh ⇒ Object
This method lets you refresh the tasks int the tasks array useful if you keep the object cached in memory and.
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
#description ⇒ Object
Returns the value of attribute description.
23 24 25 |
# File 'lib/shinmun/aggregations/flickr.rb', line 23 def description @description end |
#link ⇒ Object
Returns the value of attribute link.
23 24 25 |
# File 'lib/shinmun/aggregations/flickr.rb', line 23 def link @link end |
#pics ⇒ Object
Returns the value of attribute pics.
23 24 25 |
# File 'lib/shinmun/aggregations/flickr.rb', line 23 def pics @pics end |
#title ⇒ Object
Returns the value of attribute title.
23 24 25 |
# File 'lib/shinmun/aggregations/flickr.rb', line 23 def title @title end |
#url ⇒ Object
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 |
#refresh ⇒ Object
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 |