Search in sources :

Example 71 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class HtmlElementDescription method sub_elements.

@JRubyMethod()
public IRubyObject sub_elements(ThreadContext context) {
    Ruby ruby = context.getRuntime();
    List<String> subs = findSubElements(element);
    IRubyObject[] ary = new IRubyObject[subs.size()];
    for (int i = 0; i < subs.size(); ++i) {
        ary[i] = ruby.newString(subs.get(i));
    }
    return ruby.newArray(ary);
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 72 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class HtmlEntityLookup method get.

/**
     * 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;
}
Also used : IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 73 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class ReaderNode method getNamespaces.

public IRubyObject getNamespaces(ThreadContext context) {
    if (namespaces == null)
        return ruby.getNil();
    RubyHash hash = RubyHash.newHash(ruby);
    Set<String> keys = namespaces.keySet();
    for (String key : keys) {
        String stringValue = namespaces.get(key);
        IRubyObject k = stringOrBlank(context.getRuntime(), key);
        IRubyObject v = stringOrBlank(context.getRuntime(), stringValue);
        if (context.getRuntime().is1_9())
            hash.op_aset19(context, k, v);
        else
            hash.op_aset(context, k, v);
    }
    return hash;
}
Also used : RubyHash(org.jruby.RubyHash) NokogiriHelpers.rubyStringToString(nokogiri.internals.NokogiriHelpers.rubyStringToString) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 74 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class XsltExtensionFunction method call.

public static Object call(String method, Object arg) {
    if (XsltStylesheet.getRegistry() == null)
        return null;
    ThreadContext context = (ThreadContext) XsltStylesheet.getRegistry().get("context");
    IRubyObject receiver = (IRubyObject) XsltStylesheet.getRegistry().get("receiver");
    if (context == null || receiver == null)
        return null;
    IRubyObject arg0 = JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), arg);
    IRubyObject result = RuntimeHelpers.invoke(context, receiver, method, arg0);
    return result.toJava(Object.class);
}
Also used : ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Example 75 with IRubyObject

use of org.jruby.runtime.builtin.IRubyObject in project gocd by gocd.

the class NokogiriXPathFunction method evaluate.

public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != this.arity) {
        throw new XPathFunctionException("arity does not match");
    }
    Ruby ruby = this.handler.getRuntime();
    ThreadContext context = ruby.getCurrentContext();
    IRubyObject result = RuntimeHelpers.invoke(context, this.handler, this.name, fromObjectToRubyArgs(args));
    return fromRubyToObject(result);
}
Also used : XPathFunctionException(javax.xml.xpath.XPathFunctionException) ThreadContext(org.jruby.runtime.ThreadContext) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Aggregations

IRubyObject (org.jruby.runtime.builtin.IRubyObject)105 JRubyMethod (org.jruby.anno.JRubyMethod)32 Document (org.w3c.dom.Document)27 Ruby (org.jruby.Ruby)25 Node (org.w3c.dom.Node)24 RubyString (org.jruby.RubyString)16 RubyArray (org.jruby.RubyArray)13 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)11 RaiseException (org.jruby.exceptions.RaiseException)10 InputStream (java.io.InputStream)6 ClojureTest (org.enumerable.lambda.support.clojure.ClojureTest)6 GroovyTest (org.enumerable.lambda.support.groovy.GroovyTest)6 JavaScriptTest (org.enumerable.lambda.support.javascript.JavaScriptTest)6 LambdaJRuby (org.enumerable.lambda.support.jruby.LambdaJRuby)6 ScalaTest (org.enumerable.lambda.support.scala.ScalaTest)6 RubyProc (org.jruby.RubyProc)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)4 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)4