Sha256: 707ead7382cf55afb167871917779ea5a78798ca0f7cdfbcb05389f0cb02e80f

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

require 'iconv'
module Eightball

	def eightball
		string = self.encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace)
		begin
    		string.empty?
  		rescue ArgumentError => e
	    	if e.message == "invalid byte sequence in UTF-8"
	      		Thread.current["iconv"] ||= Iconv.new('UTF-8//IGNORE', 'UTF-8')
	      		string = Thread.current["iconv"].iconv(string)
	    	else
	      		raise
	    	end
  		end
  		#drop the BOM
    string.force_encoding("UTF-8").gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), '')
	end

end

String.send(:include, Eightball)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eightball-0.1.3 lib/eightball.rb