Cannot dump FeedNormalizer Feed objects using YAML

Hi,
I’m downloading and parsing an RSS/Atom feed using open-uri and
feed-normalizer and trying to save the parsed feed as yaml.

Sample code below:

%w(rubygems open-uri feed-normalizer yaml).each {|lib| require lib}
YAML.dump(FeedNormalizer::FeedNormalizer.parse(open(“http://waxy.org/links/index.xml”)))

Gives:

TypeError: can’t dump anonymous class Class

I read elsewhere on the list about why Class-es cannot be dumped, but
I have no clue why trying to dump a FeedNormalizer::Feed object causes
this error(Don’t know where to look).

Has anyone done this sort of thing before? Is there any painless
workaround to this?

Thanks in advance!
Shajith

Is there any painless workaround to this?

Either use Marshal.dump instead, or set parser to nil on the feed object
before YAMLification:

feed = FeedNormalizer.parse(open(“Waxy.org”))
feed.parser = nil # [1]
YAML.dump(feed) # now it should work…

[1] or maybe feed.parser = feed.parser.to_s if you don’t

want to lose meta info.

I intend to fix this in the next release so that pre-serialization
object tampering isn’t required :slight_smile:

Hope that helps.

Andy

On 6/23/07, Andy S. [email protected] wrote:

Either use Marshal.dump instead, or set parser to nil on the feed object
before YAMLification:

Ah, so that’s what I need to zero out. I need to use YAML because I
want to keep the data human-inspectable.

Much thanks, and looking forward to the next release.

Shajith