Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (37 sloc) 0.999 kb
module Sogger
class Sogger
class << self; attr_accessor :save_path end
attr_reader :raw_data
SO_FEED_URL = "http://stackoverflow.com/feeds"
DEFAULT_SAVE_PATH = ::Tempfile.new("sogger_feed.xml").path
self.save_path = DEFAULT_SAVE_PATH
def initialize(questions = [])
@questions = questions
end
def questions
@questions.sort
end
def download_feed!
@raw_data = open(SO_FEED_URL).read
parse_raw_data
end
def save!
File.open(self.class.save_path, "w") do |file|
file.write @raw_data
end
end
def load!
@raw_data = File.read(self.class.save_path)
parse_raw_data
end
def -(other)
newest_other = other.questions.first
Sogger.new(questions.select{|q| q < newest_other })
end
private
def parse_raw_data
@data = Nokogiri::XML(@raw_data)
@questions = @data.css('entry').map{ |e| Question.from_xml(e) }
end
end
end
Jump to Line
Something went wrong with that request. Please try again.