Hi all-
I am working with a site that will be pulling down feeds from a lot of different sources, and then saving those streams into a common model, in this case a trait. An example of the code from within the FeedEntry class might be:
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
...
def self.add_entries(entries)
entries.each do |entry|
# Should know how to parse itself into a trait
@trait = parse(entry)
if @trait.save
...
end
end
Admittedly I come from a java background, and in java here, I would set up an inheritance heirarchy, and then on each subclass of FeedEntry extend the parse method so that each FeedEntry knew how to parse itself. So my questions:
1) Is this a feasible plan in rails?
2) If so, would one just include a column that was basically "type" that said what subclass the FeedEntry was?
3) If not, any suggestions on the DRYest way to do this?
Thanks!