class Nokogiri::HTML::Document

def meta_encoding

then nil is returned.
Get the meta tag encoding for this document. If there is no meta tag,
##
def meta_encoding
  case
  when meta = at('//meta[@charset]')
    meta[:charset]
  when meta = meta_content_type
    meta['content'][/charset\s*=\s*([\w-]+)/i, 1]
  end
end