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", }
Instance Method Summary collapse
-
#initialize(section, page) ⇒ Reader
constructor
A new instance of Reader.
- #link_start ⇒ Object
- #links ⇒ Object
- #page_data ⇒ Object
- #parse_description(description) ⇒ Object
- #parse_guid(guid) ⇒ Object
Constructor Details
#initialize(section, page) ⇒ Reader
Returns a new instance of Reader.
41 42 43 44 |
# File 'lib/reddit.rb', line 41 def initialize(section, page) @section = section @page = page end |
Instance Method Details
#link_start ⇒ Object
72 73 74 |
# File 'lib/reddit.rb', line 72 def link_start @page * 25 end |
#links ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/reddit.rb', line 46 def links index=0 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 = parse_description((item/:description).inner_html) Link.new(rank, site_id, title, date, url) end end |
#page_data ⇒ Object
67 68 69 70 |
# File 'lib/reddit.rb', line 67 def page_data params = "?count=#{link_start}" doc = Hpricot.XML(open("#{Urls[@section]}#{params}")) end |
#parse_description(description) ⇒ Object
63 64 65 |
# File 'lib/reddit.rb', line 63 def parse_description(description) DescriptionRegExp.match(description)[1] end |
#parse_guid(guid) ⇒ Object
59 60 61 |
# File 'lib/reddit.rb', line 59 def parse_guid(guid) GuidRegExp.match(guid)[1] end |