When you have input where Ruby or OS has incorrectly assign encoding, then conversions will not work. That's because Ruby will start with the wrong assumption and try to maintain the wrong characters when converting.
However, if you know from some other source what the correct encoding is, you can use force_encoding
method to tell Ruby how to interpret the bytes it has loaded into a String
. Note this alters the object in place.
E.g.
contents = final.body
contents.force_encoding( 'ISO-8859-8' )
puts contents
At this point (provided it works), you now can make conversions (to e.g. UTF-8), because Ruby has been correctly told what characters it is dealing with.
I could not find 'ISO-8859-8-I'
on my version of Ruby. I am not sure yet how close 'ISO-8859-8'
is to what you need (some Googling suggests that it may be OK for you, if the ...-I
encoding is not available).