How can I make this more readable?
public class RssFeed
{
string url = "http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master";
public string responseBody;
private string DATE_FORMAT = "ddd, dd MMM yyyy HH:mm:ss \\E\\D\\T";
public Story[] Getstories()
{
getContent();
var stories = Parse(responseBody);
return GetMostRecent5(stories, new StoryComparer());
}
public void getContent()
{
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
WebResponse response = req.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
responseBody = sr.ReadToEnd();
}
static Story[] Parse(string content)
{
var items = new List<string>();
int start = 0;
while (true)
{
var nextItemStart = content.IndexOf("<item>", start);
var nextItemEnd = content.IndexOf("</item>", nextItemStart);
if (nextItemStart < 0 || nextItemEnd < 0) break;
String nextItem = content.Substring(nextItemStart, nextItemEnd + 7 - nextItemStart);
items.Add(nextItem);
start = nextItemEnd;
}
var stories = new List<Story>();
for (byte i = 0; i < items.Count; i++)
{
stories.Add(new Story() {
title = Regex.Match(items[i], "(?<=<title>).*(?=</title>)").Value,
link = Regex.Match(items[i], "(?<=<link>).*(?=</link>)").Value,
date = Regex.Match(items[i], "(?<=<pubDate>).*(?=</pubdate>)").Value
});
}
return stories.ToArray();
}
private static T[] GetMostRecent5<T>(T[] stories, IComparer<T> comparer)
{
List<T> recentStories = stories.Take(5).ToList();
recentStories.Sort(comparer);
var recentStoriesArray = new T[5];
for (int i = 0; i <= 5; i++)
{
recentStoriesArray[i] = recentStories[i];
}
return recentStoriesArray;
}
public class Story
{
public string title;
public string link;
public string date;
public override bool Equals(object obj)
{
return this.Equals(obj as Story);
}
public bool Equals(Story story)
{
return this.link == story.link;
}
}
private class StoryComparer : IComparer<Story>
{
public int Compare(Story x, Story y)
{
if (x.Equals(y))
return 0;
//redundant else
else
return x.date.CompareTo(y.date);
}
}
}