I am using the SimpleRSS gem to parse a WordPress RSS feed. The only problem is that many characters in that feed are encoded using numeric codes, e.g.
’
instead of
'
Files
*rss_helper.rb*
module RssHelper
require 'rubygems'
require 'simple-rss'
require 'open-uri'
def rss
rss = SimpleRSS.parse open('http://example.com/feed/')
end
end
show.html.slim
...
-rss.entries.each do |entry|
=entry.title
With the entry.title, I have tried:
=entry.title.encode("UTF-8")
=entry.title.encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace, :replace => '')
Neither has worked. I found a lot of resources regarding the iconv gem, but from what I understand it is deprecated now.
I also attempted using the .force_encoding method instead of .encoding, but no matter what I choose it always displays that numeric code directly from the feed.
How do I force it to render the proper character?
EDIT: Here is my final helper using the gem suggested by the selected answer, included here so anyone who views this can see what I did.
*rss_helper.rb*
def decode(string)
coder = HTMLEntities.new
return coder.decode(string)
end
show.html.slim
...
decode(entry.title)
...
Run it through HTMLEntities.
This’ll translate the entity-encoded characters into their literal equivalents.