Class: Reddit::Reader
- Inherits:
-
Object
- Object
- Reddit::Reader
- Defined in:
- lib/reddit.rb
Constant Summary collapse
- GuidRegExp =
/id=t3_(.+)$/
- DescriptionRegExp =
/href="(.+)">\[link\]/
- Urls =
{ :hot => "http://reddit.com/.rss", :new => "http://reddit.com/new.rss", }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(section, page) ⇒ Reader
constructor
A new instance of Reader.
- #links ⇒ Object
Constructor Details
#initialize(section, page) ⇒ Reader
Returns a new instance of Reader.
32 33 34 35 |
# File 'lib/reddit.rb', line 32 def initialize(section, page) @page = page @feed_url = generate_feed_url section end |
Class Method Details
.subreddit_url(subreddit) ⇒ Object
54 55 56 |
# File 'lib/reddit.rb', line 54 def self.subreddit_url(subreddit) "http://reddit.com/r/#{subreddit}/.rss" end |
Instance Method Details
#links ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/reddit.rb', line 37 def links index=0 begin collection = (page_data/:item).map do |item| rank = link_start + (index += 1) site_id = parse_guid((item/:guid).inner_html) title = (item/:title).inner_html date = (item/:"dc:date").inner_html url = CGI.unescapeHTML(parse_description((item/:description).inner_html)) Link.new(rank, site_id, url, title, date) end rescue OpenURI::HTTPError [] end end |