The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Data structures for sorting feed items

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Green

Posts: 102
Nickname: darwinian
Registered: Dec, 2005

Adam Green is the author of Ruby.Darwinianweb.com
Data structures for sorting feed items Posted: Jan 1, 2006 12:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Adam Green.
Original Post: Data structures for sorting feed items
Feed Title: ruby.darwinianweb.com
Feed URL: http://www.nemesis-one.com/rss.xml
Feed Description: Adam Green's Ruby development site
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Adam Green
Latest Posts From ruby.darwinianweb.com

Advertisement
My next step for feed aggregation is to combine all the feeds into a single RSS file with the items in reverse chronological order. As a database programmer my natural approach would be to write all of the feed items into a database and sort it in descending order on the date field. Unfortunately, I've decided to not use a database for the RubyRiver app, because I want to make this a tutorial that people can follow without having MySQL installed. I've already documented the hoops that I had to jump through to get MySQL installed in Ruby under Windows, and I don't want to put that in a tutorial. I also could use FeedTools, which looks great, but hides many of the details I want to expose. I realize that I'm imposing many artificial constraints, but as I keep saying, this is principally a teaching example, and I have strong opinions on how languages should be taught. If this was just about getting the job done, I'd be using anything that made life easier. I'll reserve database use and Feedtools for later tutorials.

Since I won't be using a database, I had planned on copying all the feed items into an array and then sorting it on the date column. Yes, I didn't know that Ruby doesn't have multi-dimensional arrays. That is exactly why I'm building some real apps in Ruby, because you can't understand a language by just reading about it. The things that aren't there don't always jump out at you. There are examples of Ruby code that will allow me to simulate a multi-dimensionay array and even sort it, but they are not the type of code I want to write, and certainly not the type of code for a tutorial.

What I am planning on doing to combine and sort the feed items is as follows:
  1. Read the details of each feed item into a separate hash with a name based on a unique id for the item.
  2. Create a single hash with the date of each item as the key and the id of its matching hash as the value.
  3. Sort this master feedlist hash on the key.
  4. Loop through the feedlist hash, and use it to point to the matching item hashes. Actually, after sorting it, the feedlist hash will be an array, but that will still work.
  5. Write the data from each item hash out into a single RSS file.
As you can see, the relational model is in my blood.

Read: Data structures for sorting feed items

Topic: Who needs a fancy media player? Previous Topic   Next Topic Topic: Dependency Injection Gone Bad

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use