ruby / rss

RSS reading and writing
BSD 2-Clause "Simplified" License
185 stars 36 forks source link

Trouble setting categories for RSS 2.0 feed #29

Closed rgarner closed 3 years ago

rgarner commented 3 years ago

Hi! I've had a similar issue to #28 today with trying to set categories on an Rss 2.0 feed. I couldn't set categories=, but I appeared to be able to do

  item.categories << 'Digital specialists'

... but when the feed was generated, I'd get

  NoMethodError:
       undefined method `to_feed' for "Digital specialists":String`

Eventually, by some trial and error and a debugger, I found that what I seemingly need to do is

  category = RSS::Maker::RSS20::Channel::Categories::Category.new(maker)
  category.content = 'Digital specialists'
  item.categories << category

Is there a shorter way of doing this, and is there a way in which I might be able to contribute to the docs to cover both this sort of example and the one from #28?

rgarner commented 3 years ago

Ah, ok, found the tests for this in this repo – I was working from lib/ruby and so was guessing!

So the above should become item.categories.new_category { |c| c.content = 'Digital Specialists' }

kou commented 3 years ago

Right.