class Mechanize::Util

Monkeypatch Mechanize for jruby until their gem is fixed. Issue: github.com/sparklemotion/mechanize/issues/209

Constants

NKF_ENCODING_MAP

Old NKF from 1.8, still bundled with JRuby and Rubinius

Public Class Methods

guess_encoding(src) click to toggle source
# File lib/mla_active_duty_status.rb, line 38
def self.guess_encoding(src)
  NKF.guess(src) || Encoding::UTF_8
end
html_unescape(s) click to toggle source
# File lib/mla_active_duty_status.rb, line 22
def self.html_unescape(s)
  return s unless s
  s.gsub(/&(\w+|#[0-9]+);/) { |match|
    number = case match
               when /&(\w+);/
                 Mechanize.html_parser::NamedCharacters[$1]
               when /&#([0-9]+);/
                 $1.to_i
             end

    number ? ([number].pack('U') rescue match) : match
  }
end