Sha256: dc179911b7652f6f8a8dd1c1b51417613c2378c0b2209c0ad117221dc85f1a11

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

package nokogiri;

import static org.jruby.javasupport.util.RuntimeHelpers.invoke;

import org.cyberneko.html.HTMLEntities;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

/**
 * @author Patrick Mahoney <pat@polycrystal.org>
 */
@JRubyClass(name="Nokogiri::HTML::EntityLookup")
public class HtmlEntityLookup extends RubyObject {

    public HtmlEntityLookup(Ruby runtime, RubyClass rubyClass) {
        super(runtime, rubyClass);
    }

    /**
     * Looks up an HTML entity <code>key</code>.
     *
     * The description is a bit lacking.
     */
    @JRubyMethod()
    public IRubyObject get(ThreadContext context, IRubyObject key) {
        Ruby ruby = context.getRuntime();
        String name = key.toString();
        int val = HTMLEntities.get(name);
        if (val == -1) return ruby.getNil();

        IRubyObject edClass =
            ruby.getClassFromPath("Nokogiri::HTML::EntityDescription");
        IRubyObject edObj = invoke(context, edClass, "new",
                                   ruby.newFixnum(val), ruby.newString(name),
                                   ruby.newString(name + " entity"));

        return edObj;
    }

}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nokogiri-1.5.0.beta.2 ext/java/nokogiri/HtmlEntityLookup.java
nokogiri-1.5.0.beta.2-java ext/java/nokogiri/HtmlEntityLookup.java