jeudi 8 octobre 2015

Nokogiri parse only if string is html encoded

I have a situation where I receive html encoded information in our database column in some instance, in some other instances I receive regular text.

So I have this code:

my_string = Nokogiri::HTML.parse(my_string).text

This works if my_string is html encoded but does not work if it's regular text.

Is there a way I can perform the following check?

if html_encoded, Nokigiri::HTML.parse else just return as is

.

Aucun commentaire:

Enregistrer un commentaire