Class: Mechanize::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/mla_active_duty_status.rb

Overview

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

Class Method Summary collapse

Class Method Details

.html_unescape(s) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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